Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ConvTranspose: enhance attribute check #3000

Merged
merged 13 commits into from Sep 14, 2020
4 changes: 4 additions & 0 deletions onnx/defs/nn/defs.cc
Expand Up @@ -1191,6 +1191,10 @@ void convTransposeShapeInference(InferenceContext& ctx) {
if (pads.size() != n_input_dims * 2) {
fail_shape_inference("Attribute pads has incorrect size");
}
const auto* auto_pad_attr = ctx.getAttribute("auto_pad");
if (nullptr != auto_pad_attr) {
fail_shape_inference("The pads attribute cannot be used simultaneously with auto_pad attribute");
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a minor nit: this is neither a shape_inference error nor a type_inference error. Unfortunately, we have only "fail_type_inference" and "fail_shape_inference". This is okay, but it might be good to have a consistent categorization of errors (may be adding another category of errors) ... not necessarily in this PR, could be later also.

}
} else {
pads.assign(n_input_dims * 2, 0);
const auto* auto_pad_attr = ctx.getAttribute("auto_pad");
Expand Down
10 changes: 10 additions & 0 deletions onnx/test/shape_inference_test.py
Expand Up @@ -1537,6 +1537,16 @@ def test_conv_transpose_with_group_and_output_shape(self): # type: () -> None
[])
self._assert_inferred(graph, [make_tensor_value_info('Y', TensorProto.FLOAT, (25, 64, 36, 36))])

def test_conv_transpose_with_pads_and_auto_pads(self): # type: () -> None
# This test should fail because pads cannot be used simultaneously with auto_pad
graph = self._make_graph(
[('X', TensorProto.FLOAT, (1, 1, 2, 2)),
('W', TensorProto.FLOAT, (1, 1, 3, 3)),
('B', TensorProto.FLOAT, (1, ))],
[make_node('ConvTranspose', ['X', 'W', 'B'], 'Y', auto_pad="SAME_UPPER", strides=[1, 1], pads=[0, 1, 1, 0])],
[])
self.assertRaises(RuntimeError, onnx.shape_inference.infer_shapes, helper.make_model(graph))

def test_mvn_function_output_shape(self): # type: () -> None
graph = self._make_graph(
[('X', TensorProto.FLOAT, (25, 48, 16, 16))],
Expand Down