Skip to content

Commit

Permalink
Fix activity regularizer + model composition test
Browse files Browse the repository at this point in the history
  • Loading branch information
fchollet committed Feb 13, 2018
1 parent 87a6182 commit c42f9b0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/keras/engine/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,25 +658,26 @@ def test_recursion_with_bn_and_loss():

@keras_test
def test_activity_regularization_with_model_composition():
# Ensures that the shape of the input to the activity
# regularizer is the same under model composition.
# Tests for regressions of issue #9267
wrong_size = 10
correct_size = 2

def reg(x):
assert x.shape[-1] == correct_size
return 0
return K.sum(x)

net_a_input = Input([2])
net_a_input = Input((2,))
net_a = net_a_input
net_a = Dense(wrong_size)(net_a)
net_a = Dense(correct_size, activity_regularizer=reg)(net_a)
net_a = Dense(2, kernel_initializer='ones',
use_bias=False,
activity_regularizer=reg)(net_a)
model_a = Model([net_a_input], [net_a])

net_b_input = Input([2])
net_b = Dense(10)(model_a(net_b_input))
net_b_input = Input((2,))
net_b = model_a(net_b_input)
model_b = Model([net_b_input], [net_b])

model_b.compile(optimizer='sgd', loss=None)
x = np.ones((1, 2))
loss = model_b.evaluate(x)
assert loss == 4


@keras_test
def test_shared_layer_depth_is_correct():
Expand Down

0 comments on commit c42f9b0

Please sign in to comment.