jwfromm commented on a change in pull request #5135: [ONNX]Pool3d & upsample3d
op support
URL: https://github.com/apache/incubator-tvm/pull/5135#discussion_r396796719
##########
File path: python/tvm/relay/frontend/onnx.py
##########
@@ -780,19 +784,36 @@ def _impl_v9(cls, inputs, attr, params):
assert len(inputs) == 2, "Upsample op take 2 inputs, {}
given".format(len(inputs))
scales = params[inputs[1].name_hint].asnumpy()
inputs = inputs[:1]
- assert len(scales) == 4 and scales[0] == 1.0 and scales[1] == 1.0
+ assert scales[0] == 1.0 and scales[1] == 1.0
+ input_shape = infer_shape(inputs[0])
+ dims = len(input_shape)
+ isUpSample3D = bool(dims == 5)
mode = attr.get('mode')
if mode == b'nearest':
method = "nearest_neighbor"
elif mode == b'linear':
- method = "bilinear"
+ method = "trilinear" if isUpSample3D else "bilinear"
else:
raise tvm.error.OpAttributeInvalid(
'Value {} in attribute "mode" of operator Upsample is not
valid.'.format(mode))
- attr = {'scale_h': scales[-2], 'scale_w': scales[-1], 'method': method,
- 'layout': 'NCHW', 'align_corners': True}
- return AttrCvt('upsampling')(inputs, attr)
-
+ if isUpSample3D:
+ assert len(scales) == 5
+ attr = {'scale_d': scales[-3],
+ 'scale_h': scales[-2],
+ 'scale_w': scales[-1],
+ 'method': method,
+ 'layout': 'NCDHW',
+ 'coordinate_transformation_mode':'half_pixel'}
+ op_name = 'upsampling3d'
+ else:
+ assert len(scales) == 4
+ attr = {'scale_h': scales[-2],
+ 'scale_w': scales[-1],
+ 'method': method,
+ 'layout': 'NCHW',
+ 'align_corners': True}
Review comment:
Since many of these attributes are shared between 2d and 3d, it'd be more
space efficient to define the shared attributes then update the missing /
different bits inside the if/else.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services