Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Parametrized tests.
  • Loading branch information
gabrieldemarmiesse committed Aug 29, 2018
commit dac12e983c66f75cd24b8845054a108359a8df72
57 changes: 29 additions & 28 deletions tests/keras/layers/convolutional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,41 +864,42 @@ def test_upsampling_2d():

@pytest.mark.skipif((K.backend() == 'cntk'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this test parameterized (see #10975)

reason='cntk does not support it yet')
def test_upsampling_2d_bilinear():
@pytest.mark.parametrize('data_format',
['channels_first', 'channels_last'])
def test_upsampling_2d_bilinear(data_format):
num_samples = 2
stack_size = 2
input_num_row = 11
input_num_col = 12

for data_format in ['channels_first', 'channels_last']:
if data_format == 'channels_first':
inputs = np.random.rand(num_samples, stack_size, input_num_row,
input_num_col)
else: # tf
inputs = np.random.rand(num_samples, input_num_row, input_num_col,
stack_size)
if data_format == 'channels_first':
inputs = np.random.rand(num_samples, stack_size, input_num_row,
input_num_col)
else: # tf
inputs = np.random.rand(num_samples, input_num_row, input_num_col,
stack_size)

# basic test
layer_test(convolutional.UpSampling2D,
kwargs={'size': (2, 2),
'data_format': data_format,
'interpolation': 'bilinear'},
input_shape=inputs.shape)
# basic test
layer_test(convolutional.UpSampling2D,
kwargs={'size': (2, 2),
'data_format': data_format,
'interpolation': 'bilinear'},
input_shape=inputs.shape)

for length_row in [2]:
for length_col in [2, 3]:
layer = convolutional.UpSampling2D(
size=(length_row, length_col),
data_format=data_format)
layer.build(inputs.shape)
outputs = layer(K.variable(inputs))
np_output = K.eval(outputs)
if data_format == 'channels_first':
assert np_output.shape[2] == length_row * input_num_row
assert np_output.shape[3] == length_col * input_num_col
else: # tf
assert np_output.shape[1] == length_row * input_num_row
assert np_output.shape[2] == length_col * input_num_col
for length_row in [2]:
for length_col in [2, 3]:
layer = convolutional.UpSampling2D(
size=(length_row, length_col),
data_format=data_format)
layer.build(inputs.shape)
outputs = layer(K.variable(inputs))
np_output = K.eval(outputs)
if data_format == 'channels_first':
assert np_output.shape[2] == length_row * input_num_row
assert np_output.shape[3] == length_col * input_num_col
else: # tf
assert np_output.shape[1] == length_row * input_num_row
assert np_output.shape[2] == length_col * input_num_col


@pytest.mark.skipif((K.backend() == 'cntk'),
Expand Down