Skip to content

Commit

Permalink
fixed Merge Layer functional API (#2460)
Browse files Browse the repository at this point in the history
* fixed Merge Layer functional API

* moved test to layers/test_core
  • Loading branch information
lewisacidic authored and fchollet committed Apr 23, 2016
1 parent f84389d commit 5f4019d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions keras/engine/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,9 @@ def __call__(self, inputs, mask=None):
node_indices, tensor_indices)
self.built = True
self.add_inbound_node(layers, node_indices, tensor_indices)

outputs = self.inbound_nodes[-1].output_tensors
return outputs[0] # merge only returns a single tensor
else:
return self.call(inputs, mask)

Expand Down
12 changes: 11 additions & 1 deletion tests/keras/layers/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_masking():


def test_merge():
from keras.layers import Input, merge
from keras.layers import Input, merge, Merge
from keras.models import Model

# test modes: 'sum', 'mul', 'concat', 'ave', 'cos', 'dot'.
Expand All @@ -38,6 +38,16 @@ def test_merge():
model = Model.from_config(config)
model.compile('rmsprop', 'mse')

# test Merge (#2460)
merged = Merge(mode=mode)([input_a, input_b])
model = Model([input_a, input_b], merged)
model.compile('rmsprop', 'mse')

expected_output_shape = model.get_output_shape_for(input_shapes)
actual_output_shape = model.predict(inputs).shape
assert expected_output_shape == actual_output_shape


# test lambda with output_shape lambda
input_a = Input(shape=input_shapes[0][1:])
input_b = Input(shape=input_shapes[1][1:])
Expand Down

0 comments on commit 5f4019d

Please sign in to comment.