Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix lint
  • Loading branch information
Xingyu Zhou committed Oct 27, 2019
commit 068e4f289c7c477a15666b68abbb217e02b4f958
3 changes: 2 additions & 1 deletion python/tvm/relay/frontend/coreml.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ def _UpsampleLayerParams(op, inexpr, etab):
raise tvm.error.OpAttributeUnimplemented(
'Upsample height and width must be equal.')
interpolationMode = 'nearest_neighbor' if op.mode == 0 else 'bilinear'
return _op.nn.upsampling(inexpr, scaleH=op.scalingFactor[0], scaleW=op.scalingFactor[1], method=interpolationMode)
return _op.nn.upsampling(inexpr, scaleH=op.scalingFactor[0],
scaleW=op.scalingFactor[1], method=interpolationMode)


def _L2NormalizeLayerParams(op, inexpr, etab):
Expand Down
3 changes: 2 additions & 1 deletion python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ def _impl_v9(cls, inputs, attr, params):
else:
raise tvm.error.OpAttributeInvalid(
'Value {} in attribute "mode" of operator Upsample is not valid.'.format(mode))
attr = {'scaleH':scales[-2], 'scaleW':scales[-1], 'method':method, 'layout':'NCHW', 'align_corners':True}
attr = {'scaleH':scales[-2], 'scaleW':scales[-1], 'method':method,
'layout':'NCHW', 'align_corners':True}
return AttrCvt('upsampling')(inputs, attr)


Expand Down
6 changes: 4 additions & 2 deletions tests/python/relay/test_op_level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def test_upsampling_infer_type():
y = relay.nn.upsampling(x, scaleH=2, scaleW=2, layout="NCHW", method="bilinear")
"method=\"BINLINEAR\"" in y.astext()
yy = run_infer_type(y)
assert yy.checked_type == relay.TensorType((n, c, tvm.expr.Cast("int32", tvm.round(h*scale)), tvm.expr.Cast("int32", tvm.round(w*scale))), "float32")
assert yy.checked_type == relay.TensorType((n, c, tvm.expr.Cast("int32", tvm.round(h*scale)),
tvm.expr.Cast("int32", tvm.round(w*scale))), "float32")
n, c = tvm.var("n"), tvm.var("c")
x = relay.var("x", relay.TensorType((n, c, 100, 200), "float32"))
y = relay.nn.upsampling(x, scaleH=2, scaleW=2, layout="NCHW", method="bilinear")
Expand Down Expand Up @@ -528,7 +529,8 @@ def get_shape():
if method == "nearest_neighbor":
ref = topi.testing.upsampling_python(data, (scaleH, scaleW), layout)
else:
ref = topi.testing.bilinear_resize_python(data, (int(round(h*scaleH)), int(round(w*scaleW))), layout)
ref = topi.testing.bilinear_resize_python(data, (int(round(h*scaleH)),
int(round(w*scaleW))), layout)
for target, ctx in ctx_list():
executor = relay.create_executor("graph", ctx=ctx, target=target)
out = executor.evaluate(func)(data)
Expand Down
6 changes: 4 additions & 2 deletions topi/python/topi/nn/upsampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ def upsampling(data, scaleH, scaleW, layout="NCHW", method='nearest_neighbor', a
"""
base_layout = layout[0:4]
if base_layout == "NCHW":
out_shape = (simplify(topi.cast(tvm.round(data.shape[2] * scaleH), data.shape[2].dtype)), simplify(topi.cast(tvm.round(data.shape[3] * scaleW), data.shape[3].dtype)))
out_shape = (simplify(topi.cast(tvm.round(data.shape[2] * scaleH), data.shape[2].dtype)),
simplify(topi.cast(tvm.round(data.shape[3] * scaleW), data.shape[3].dtype)))
elif layout == "NHWC":
out_shape = (simplify(topi.cast(tvm.round(data.shape[1] * scaleH), data.shape[1].dtype)), simplify(topi.cast(tvm.round(data.shape[2] * scaleW), data.shape[2].dtype)))
out_shape = (simplify(topi.cast(tvm.round(data.shape[1] * scaleH), data.shape[1].dtype)),
simplify(topi.cast(tvm.round(data.shape[2] * scaleW), data.shape[2].dtype)))

else:
raise ValueError("not support this layout {} yet".format(layout))
Expand Down