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

Refactor bilinear and neighbour implementation in Tensorflow frontend #4504

Merged
Merged
Changes from all commits
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
27 changes: 6 additions & 21 deletions python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ def _impl(inputs, attr, params):
extras={'axis': int(axis), 'num_newaxis': 1})(inputs, attr)
return _impl

def _resize_bilinear():
def _resize_bilinear(bilinear_op):
def _impl(inputs, attr, params):
size = attr['_output_shapes'][0][1:3]
# Important that the size is defined. If an axis is not, we need to infer what
Expand All @@ -429,24 +429,9 @@ def _impl(inputs, attr, params):
attr['layout'] = 'NHWC'

# Ignore the new attributes from TF2.0, for now.
return AttrCvt(op_name="resize",
return AttrCvt(op_name='resize',
ignores=['Tdim', 'half_pixel_centers'],
extras={'method': "bilinear"})(inputs, attr)
return _impl

def _resize_nearest_neighbor():
def _impl(inputs, attr, params):
size = attr['_output_shapes'][0][1:3]
if -1 in size:
size = _infer_value(inputs[1], params).asnumpy().reshape([-1]).tolist()
attr['size'] = size
inputs.pop(1)
# NHWC
attr['layout'] = 'NHWC'

return AttrCvt(op_name="resize",
ignores=['Tdim'],
extras={'method': "nearest_neighbor"})(inputs, attr)
extras={'method': bilinear_op})(inputs, attr)
return _impl

def _check_numerics():
Expand Down Expand Up @@ -1503,9 +1488,9 @@ def _impl(inputs, attr, params):
'Relu' : AttrCvt('relu'),
'Relu6' : _relu6(),
'Reshape' : _reshape(),
'ResizeBilinear' : _resize_bilinear(),
'ResizeBicubic' : _resize_bilinear(),
'ResizeNearestNeighbor' : _resize_nearest_neighbor(),
'ResizeBilinear' : _resize_bilinear('bilinear'),
'ResizeBicubic' : _resize_bilinear('bilinear'),
'ResizeNearestNeighbor' : _resize_bilinear('nearest_neighbor'),
'ReverseV2' : _reverse_v2(),
'RightShift' : AttrCvt('right_shift'),
'Round' : AttrCvt('round'),
Expand Down