Skip to content

Commit

Permalink
Merge pull request deepchem#794 from peastman/inlayers
Browse files Browse the repository at this point in the history
Can pass input layers by position
  • Loading branch information
rbharath authored Aug 26, 2017
2 parents a1ad561 + dca6d7f commit 84c49cf
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions deepchem/models/tensorgraph/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ def _get_scope_name(self):
class Flatten(Layer):
"""Flatten every dimension except the first"""

def __init__(self, **kwargs):
super(Flatten, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(Flatten, self).__init__(in_layers, **kwargs)
try:
parent_shape = self.in_layers[0].shape
s = list(parent_shape[:2])
Expand Down Expand Up @@ -425,9 +425,9 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class Squeeze(Layer):

def __init__(self, squeeze_dims=None, **kwargs):
def __init__(self, in_layers=None, squeeze_dims=None, **kwargs):
self.squeeze_dims = squeeze_dims
super(Squeeze, self).__init__(**kwargs)
super(Squeeze, self).__init__(in_layers, **kwargs)
try:
parent_shape = self.in_layers[0].shape
if squeeze_dims is None:
Expand Down Expand Up @@ -472,8 +472,8 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class CombineMeanStd(Layer):

def __init__(self, **kwargs):
super(CombineMeanStd, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(CombineMeanStd, self).__init__(in_layers, **kwargs)
try:
self._shape = self.in_layers[0].shape
except:
Expand Down Expand Up @@ -650,8 +650,8 @@ def __init__(self, **kwargs):

class L1Loss(Layer):

def __init__(self, **kwargs):
super(L1Loss, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(L1Loss, self).__init__(in_layers, **kwargs)

def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):
inputs = self._get_input_tensors(in_layers, True)
Expand All @@ -665,8 +665,8 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class L2Loss(Layer):

def __init__(self, **kwargs):
super(L2Loss, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(L2Loss, self).__init__(in_layers, **kwargs)
try:
shape1 = self.in_layers[0].shape
shape2 = self.in_layers[1].shape
Expand All @@ -689,8 +689,8 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class SoftMax(Layer):

def __init__(self, **kwargs):
super(SoftMax, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(SoftMax, self).__init__(in_layers, **kwargs)
try:
self._shape = tuple(self.in_layers[0].shape)
except:
Expand All @@ -709,9 +709,9 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class Concat(Layer):

def __init__(self, axis=1, **kwargs):
def __init__(self, in_layers=None, axis=1, **kwargs):
self.axis = axis
super(Concat, self).__init__(**kwargs)
super(Concat, self).__init__(in_layers, **kwargs)
try:
s = list(self.in_layers[0].shape)
for parent in self.in_layers[1:]:
Expand All @@ -734,9 +734,9 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class Stack(Layer):

def __init__(self, axis=1, **kwargs):
def __init__(self, in_layers=None, axis=1, **kwargs):
self.axis = axis
super(Stack, self).__init__(**kwargs)
super(Stack, self).__init__(in_layers, **kwargs)
try:
s = list(self.in_layers[0].shape)
s.insert(axis, len(self.in_layers))
Expand Down Expand Up @@ -810,7 +810,7 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):
class Add(Layer):
"""Compute the (optionally weighted) sum of the input layers."""

def __init__(self, weights=None, **kwargs):
def __init__(self, in_layers=None, weights=None, **kwargs):
"""Create an Add layer.
Parameters
Expand All @@ -819,7 +819,7 @@ def __init__(self, weights=None, **kwargs):
an array of length equal to the number of input layers, giving the weight
to multiply each input by. If None, all weights are set to 1.
"""
super(Add, self).__init__(**kwargs)
super(Add, self).__init__(in_layers, **kwargs)
self.weights = weights
try:
shape1 = list(self.in_layers[0].shape)
Expand Down Expand Up @@ -854,8 +854,8 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):
class Multiply(Layer):
"""Compute the product of the input layers."""

def __init__(self, **kwargs):
super(Multiply, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(Multiply, self).__init__(in_layers, **kwargs)
try:
shape1 = list(self.in_layers[0].shape)
shape2 = list(self.in_layers[1].shape)
Expand Down Expand Up @@ -908,8 +908,8 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class SparseSoftMaxCrossEntropy(Layer):

def __init__(self, **kwargs):
super(SparseSoftMaxCrossEntropy, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(SparseSoftMaxCrossEntropy, self).__init__(in_layers, **kwargs)
try:
self._shape = (self.in_layers[1].shape[0], 1)
except:
Expand All @@ -930,8 +930,8 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class SoftMaxCrossEntropy(Layer):

def __init__(self, **kwargs):
super(SoftMaxCrossEntropy, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(SoftMaxCrossEntropy, self).__init__(in_layers, **kwargs)
try:
self._shape = (self.in_layers[1].shape[0], 1)
except:
Expand All @@ -952,9 +952,9 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class ReduceMean(Layer):

def __init__(self, axis=None, **kwargs):
def __init__(self, in_layers=None, axis=None, **kwargs):
self.axis = axis
super(ReduceMean, self).__init__(**kwargs)
super(ReduceMean, self).__init__(in_layers, **kwargs)
if axis is None:
self._shape = tuple()
else:
Expand All @@ -981,8 +981,8 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class ToFloat(Layer):

def __init__(self, **kwargs):
super(ToFloat, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(ToFloat, self).__init__(in_layers, **kwargs)
try:
self._shape = tuple(self.in_layers[0].shape)
except:
Expand All @@ -1000,9 +1000,9 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class ReduceSum(Layer):

def __init__(self, axis=None, **kwargs):
def __init__(self, in_layers=None, axis=None, **kwargs):
self.axis = axis
super(ReduceSum, self).__init__(**kwargs)
super(ReduceSum, self).__init__(in_layers, **kwargs)
if axis is None:
self._shape = tuple()
else:
Expand All @@ -1029,9 +1029,9 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class ReduceSquareDifference(Layer):

def __init__(self, axis=None, **kwargs):
def __init__(self, in_layers=None, axis=None, **kwargs):
self.axis = axis
super(ReduceSquareDifference, self).__init__(**kwargs)
super(ReduceSquareDifference, self).__init__(in_layers, **kwargs)
if axis is None:
self._shape = tuple()
else:
Expand Down Expand Up @@ -1792,8 +1792,8 @@ def set_tensors(self, tensor):

class BatchNorm(Layer):

def __init__(self, **kwargs):
super(BatchNorm, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(BatchNorm, self).__init__(in_layers, **kwargs)
try:
parent_shape = self.in_layers[0].shape
self._shape = tuple(self.in_layers[0].shape)
Expand Down Expand Up @@ -1855,8 +1855,8 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):

class WeightedError(Layer):

def __init__(self, **kwargs):
super(WeightedError, self).__init__(**kwargs)
def __init__(self, in_layers=None, **kwargs):
super(WeightedError, self).__init__(in_layers, **kwargs)
self._shape = tuple()

def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):
Expand Down Expand Up @@ -1991,9 +1991,9 @@ def create_tensor(self, in_layers=None, set_tensors=True, **kwargs):
class WeightedLinearCombo(Layer):
"""Computes a weighted linear combination of input layers, with the weights defined by trainable variables."""

def __init__(self, std=.3, **kwargs):
def __init__(self, in_layers=None, std=.3, **kwargs):
self.std = std
super(WeightedLinearCombo, self).__init__(**kwargs)
super(WeightedLinearCombo, self).__init__(in_layers, **kwargs)
try:
self._shape = tuple(self.in_layers[0].shape)
except:
Expand Down

0 comments on commit 84c49cf

Please sign in to comment.