Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions python/tvm/relay/frontend/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,10 +816,16 @@ def _convert_cropping(
f"Operator {crop_type} is not supported for frontend Keras."
)
int32_max = np.iinfo(np.int32).max
if data_layout == "NHWC":
begin = [0, crop_t, crop_l, 0]
end = [int32_max, in_h - crop_b, in_w - crop_r, int32_max]
else:
begin = [0, 0, crop_t, crop_l]
end = [int32_max, int32_max, in_h - crop_b, in_w - crop_r]
return _op.strided_slice(
inexpr,
begin=[0, 0, crop_t, crop_l],
end=[int32_max, int32_max, in_h - crop_b, in_w - crop_r],
begin=begin,
end=end,
)


Expand Down
10 changes: 9 additions & 1 deletion tests/python/frontend/keras/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,15 @@ def test_forward_crop(self, keras_mod):
x = keras_mod.layers.Cropping2D(cropping=0)(x)
x = keras_mod.layers.Add()([x, x])
keras_model = keras_mod.models.Model(data, x)
verify_keras_frontend(keras_model)
verify_keras_frontend(keras_model, layout="NHWC")
verify_keras_frontend(keras_model, layout="NHWC")

data = keras_mod.layers.Input(shape=(32, 32, 3))
x = keras_mod.layers.Cropping2D(cropping=(2, 1))(data)
x = keras_mod.layers.Cropping2D(cropping=(1, 2))(x)
keras_model = keras_mod.models.Model(data, x)
verify_keras_frontend(keras_model, layout="NHWC")
verify_keras_frontend(keras_model, layout="NCHW")

def test_forward_multi_inputs(self, keras_mod):
data1 = keras_mod.layers.Input(shape=(32, 32, 3))
Expand Down