From: Matthew Brookhart Date: Wed, 6 May 2020 19:36:01 +0000 (-0700) Subject: Fix an issue with Upsampling and update one test to hit the broken usecase (#5530) X-Git-Tag: upstream/0.7.0~786 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=900254d3425ba728dacbf8e5e0ce29fce8eccd3f;p=platform%2Fupstream%2Ftvm.git Fix an issue with Upsampling and update one test to hit the broken usecase (#5530) --- diff --git a/python/tvm/relay/frontend/onnx.py b/python/tvm/relay/frontend/onnx.py index 33b8ee1..ee8f2e8 100644 --- a/python/tvm/relay/frontend/onnx.py +++ b/python/tvm/relay/frontend/onnx.py @@ -787,7 +787,10 @@ class Upsample(OnnxOpConverter): 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]) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 9fe50eb..dc832aa 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -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))],