Skip to content

Commit

Permalink
Fix an issue with Upsampling and update one test to hit the broken us…
Browse files Browse the repository at this point in the history
…ecase (#5530)
  • Loading branch information
Matthew Brookhart authored May 6, 2020
1 parent 79e29ab commit 900254d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 4 additions & 1 deletion python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,10 @@ def _impl_v9(cls, inputs, attr, params):
if not scales:
#Here we are going to higher OPSET version.
assert len(inputs) == 2, "Upsample op take 2 inputs, {} given".format(len(inputs))
scales = params[inputs[1].name_hint].asnumpy()
if get_name(inputs[1]) in params:
scales = params[inputs[1].name_hint].asnumpy()
else:
scales = infer_value_simulated(inputs[1], params).asnumpy()
inputs = inputs[:1]
assert scales[0] == 1.0 and scales[1] == 1.0
input_shape = infer_shape(inputs[0])
Expand Down
13 changes: 7 additions & 6 deletions tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,21 +859,22 @@ def _test_upsample_bilinear_opset9():
in_shape = (1, 1, 3, 3)
out_shape = (1, 1, 3*scale, 3*scale)
y = helper.make_node("Upsample", ['in', 'scales'], ['out'], mode='linear')
scales = [1.0, 1.0, 2.0, 2.0]
scales = [1, 1, 2, 2]
in_array = np.random.uniform(size=in_shape).astype(np.float32)
out_array = topi.testing.bilinear_resize_python(
in_array, (3*scale, 3*scale), "NCHW")

ref_array = np.array(scales)
ref_node = helper.make_node('Constant',
inputs=[],
outputs=['scales'],
outputs=['const'],
value=onnx.helper.make_tensor(name='const_tensor',
data_type=TensorProto.FLOAT,
dims=ref_array.shape,
vals=ref_array.flatten().astype(float)))
dims=scales,
vals=np.random.random(scales).flatten().astype(float)))

graph = helper.make_graph([ref_node, y],
shape_node = helper.make_node("Shape", ['const'], ['scales'])

graph = helper.make_graph([ref_node, shape_node, y],
'upsample_bilinear_opset9_test',
inputs=[helper.make_tensor_value_info(
"in", TensorProto.FLOAT, list(in_shape))],
Expand Down

0 comments on commit 900254d

Please sign in to comment.