Commit de123760 by Josh Fromm Committed by MORITA Kazutaka

[Relay] Keras frontend upsample and 1 channel conv2d fixes (#3937)

* Fix upsample layout in keras frontend.

* Fixed group conv being used instead of conv when channels=1

* Add new conv2d test to catch bugs when channels=1.
parent fc071daf
......@@ -395,7 +395,7 @@ def _convert_pooling(inexpr, keras_layer, etab):
def _convert_upsample(inexpr, keras_layer, _):
_check_data_format(keras_layer)
upsample_type = type(keras_layer).__name__
params = {'layout': 'NHWC'}
params = {}
if upsample_type == 'UpSampling1D':
h = keras_layer.size
params['scale'] = h
......
......@@ -71,7 +71,7 @@ bool Conv2DRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
CHECK_EQ(param->dilation.size(), 2);
Array<IndexExpr> wshape;
if (tvm::ir::Equal(param->channels, param->groups)) {
if (tvm::ir::Equal(param->channels, param->groups) && !tvm::ir::Equal(param->channels, 1)) {
// infer weight's shape for depthwise convolution
wshape = {{dshape_nchw[1], param->groups / dshape_nchw[1], param->kernel_size[0],
param->kernel_size[1]}};
......
......@@ -181,6 +181,7 @@ def test_forward_conv():
strides=(2, 2), padding='same'),
keras.layers.Conv2D(filters=10, kernel_size=(3, 3),
dilation_rate=(2, 2), padding='same'),
keras.layers.Conv2D(filters=1, kernel_size=(3, 3), padding='same'),
keras.layers.DepthwiseConv2D(kernel_size=(3, 3), padding='same'),
keras.layers.Conv2DTranspose(filters=10, kernel_size=(3, 3), padding='valid'),
keras.layers.SeparableConv2D(filters=10, kernel_size=(3, 3), padding='same')]
......@@ -194,7 +195,7 @@ def test_forward_upsample(interpolation='nearest'):
data = keras.layers.Input(shape=(32, 32, 3))
x = keras.layers.UpSampling2D(size=(3, 3), interpolation=interpolation)(data)
keras_model = keras.models.Model(data, x)
verify_keras_frontend(keras_model, need_transpose=False)
verify_keras_frontend(keras_model)
def test_forward_reshape():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment