Skip to content

Commit

Permalink
[Bugfix][Relay][keras] Fix the bug about the attribute 'output_paddin…
Browse files Browse the repository at this point in the history
…g' in Deconv (apache#15060)

* fix deconv about the parameter output_padding

* add test cases to capture the in deconv

* Update keras.py
  • Loading branch information
jikechao authored and junrushao committed Jun 22, 2023
1 parent f047d2f commit 996dba3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/tvm/relay/frontend/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ def _convert_convolution(inexpr, keras_layer, etab, data_layout, input_shape=Non
params["groups"] = in_channels
else:
params["channels"] = n_filters
if is_deconv and keras_layer.output_padding:
params["output_padding"] = keras_layer.output_padding
if keras_layer.padding == "valid":
pass
# we insert a separate pad operator
Expand Down Expand Up @@ -507,6 +509,8 @@ def _convert_convolution3d(inexpr, keras_layer, etab, data_layout, input_shape=N
"kernel_layout": kernel_layout,
}
params["channels"] = n_filters
if is_deconv and keras_layer.output_padding:
params["output_padding"] = keras_layer.output_padding

if keras_layer.padding == "valid":
pass
Expand Down
6 changes: 6 additions & 0 deletions tests/python/frontend/keras/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ def test_forward_conv_transpose(self, keras_mod):
data = keras_mod.layers.Input(shape=(32, 32, 128))
conv_funcs = [
keras_mod.layers.Conv2DTranspose(filters=64, kernel_size=(2, 2), padding="valid"),
keras_mod.layers.Conv2DTranspose(
filters=2, kernel_size=(3, 3), strides=(2, 2), output_padding=(1, 1)
),
]
for conv_func in conv_funcs:
x = conv_func(data)
Expand Down Expand Up @@ -619,6 +622,9 @@ def test_forward_conv3d_transpose(self, keras_mod):
filters=1, kernel_size=(3, 3, 3), padding="valid", use_bias=False
),
keras_mod.layers.Conv3DTranspose(filters=10, kernel_size=(2, 2, 2), padding="valid"),
keras_mod.layers.Conv3DTranspose(
filters=2, kernel_size=(3, 3, 3), strides=(2, 2, 2), output_padding=(1, 1, 1)
),
]
for conv_func in conv_funcs:
x = conv_func(data)
Expand Down

0 comments on commit 996dba3

Please sign in to comment.