Commit 47057e8e authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Starting on digesting keras code

parent 7576a450
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
#from __future__ import absolute_import
import six
from keras import backend as K

def get_from_module(identifier, module_params, module_name,
@@ -24,8 +25,7 @@ def get_from_module(identifier, module_params, module_name,
    # Raises
        ValueError: if the identifier cannot be found.
    """
    #if isinstance(identifier, str) or isinstance(identifier, unicode):
    assert not isinstance(identifier, dict)
    if isinstance(identifier, six.string_types):
      res = module_params.get(identifier)
      if not res:
          raise ValueError('Invalid ' + str(module_name) + ': ' +
@@ -36,14 +36,14 @@ def get_from_module(identifier, module_params, module_name,
          return res(**kwargs)
      else:
          return res
    #elif isinstance(identifier, dict):
    #    name = identifier.pop('name')
    #    res = module_params.get(name)
    #    if res:
    #        return res(**identifier)
    #    else:
    #        raise ValueError('Invalid ' + str(module_name) + ': ' +
    #                         str(identifier))
    elif isinstance(identifier, dict):
        name = identifier.pop('name')
        res = module_params.get(name)
        if res:
            return res(**identifier)
        else:
            raise ValueError('Invalid ' + str(module_name) + ': ' +
                             str(identifier))
    return identifier

def softmax(x):
+21 −30
Original line number Diff line number Diff line
"""
Copies Classes from keras to remove dependency.

Most of this code is copied over from Keras. Hoping to use as a staging
area while we remove our Keras dependency.
"""
from __future__ import print_function
from __future__ import division
from __future__ import unicode_literals

__author__ = "Bharath Ramsundar"
__copyright__ = "Copyright 2016, Stanford University"
__license__ = "GPL"

from . import initializations
from . import regularizers
from . import activations
@@ -108,21 +107,30 @@ class Node(object):
    # and for each layer, which node and which
    # tensor output of each node.

        self.inbound_layers = inbound_layers  # List of layer instances
        self.node_indices = node_indices  # List of integers, 1:1 mapping with inbound_layers.
        self.tensor_indices = tensor_indices  # List of integers, 1:1 mapping with inbound_layers.
    # List of layer instances
    self.inbound_layers = inbound_layers  
    # List of integers, 1:1 mapping with inbound_layers.
    self.node_indices = node_indices  
    # List of integers, 1:1 mapping with inbound_layers.
    self.tensor_indices = tensor_indices  

    # Tensor inputs and outputs of outbound_layer.
        self.input_tensors = input_tensors  # List of tensors. 1:1 mapping with inbound_layers.
        self.output_tensors = output_tensors  # List of tensors, created by outbound_layer.call().
    # List of tensors. 1:1 mapping with inbound_layers.
    self.input_tensors = input_tensors  
    # List of tensors, created by outbound_layer.call().
    self.output_tensors = output_tensors  

    # input and output masks
        self.input_masks = input_masks  # List of tensors, 1:1 mapping with input_tensor.
        self.output_masks = output_masks  # List of tensors, created by outbound_layer.compute_mask().
    # List of tensors, 1:1 mapping with input_tensor.
    self.input_masks = input_masks  
    # List of tensors, created by outbound_layer.compute_mask().
    self.output_masks = output_masks  

    # input and output shapes
        self.input_shapes = input_shapes  # List of shape tuples, shapes of input_tensors.
        self.output_shapes = output_shapes  # List of shape tuples, shapes of output_tensors.
    # List of shape tuples, shapes of input_tensors.
    self.input_shapes = input_shapes  
    # List of shape tuples, shapes of output_tensors.
    self.output_shapes = output_shapes  

    # Add nodes to all layers involved.
    for layer in inbound_layers:
@@ -204,8 +212,6 @@ class Node(object):
              'node_indices': self.node_indices,
              'tensor_indices': self.tensor_indices}



class Layer(object):
  """Abstract base layer class.

@@ -357,21 +363,6 @@ class Layer(object):
  def non_trainable_weights(self, weights):
    self._non_trainable_weights = weights

    @property
    def regularizers(self):
        warnings.warn('The `regularizers` property of '
                      'layers/models is deprecated. '
                      'Regularization losses are now managed via the `losses` '
                      'layer/model property.')
        return []

    @regularizers.setter
    def regularizers(self, _):
        warnings.warn('The `regularizers` property of layers/models '
                      'is deprecated. '
                      'Regularization losses are now managed via the `losses` '
                      'layer/model property.')

  def create_input_layer(self, batch_input_shape,
                         input_dtype=None, name=None):
    if not name: