Skip to content
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
20 changes: 14 additions & 6 deletions python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,18 +1468,26 @@ class Unsqueeze(OnnxOpConverter):
"""Operator converter for Unsqueeze."""

@classmethod
def _impl_v1(cls, inputs, attr, params):
axes = sorted(attr["axes"])
def run_calculation(cls, tensor, axes):
axes = sorted(axes)
for axis in axes:
inputs[0] = _op.expand_dims(inputs[0], axis=axis, num_newaxis=1)
return inputs[0]
tensor = _op.expand_dims(tensor, axis=axis, num_newaxis=1)
return tensor

@classmethod
def _impl_v12(cls, inputs, attr, params):
def _impl_v1(cls, inputs, attr, params):
return cls.run_calculation(inputs[0], attr["axes"])

@classmethod
def _impl_v13(cls, inputs, attr, params):
if isinstance(inputs[1], _expr.Constant):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought axes could also be an Expr involving only constants, but I hope such weird usage wouldn't happen.

constant_axes = list(inputs[1].data.numpy())
constant_axes = list(map(int, constant_axes))
return cls.run_calculation(inputs[0], constant_axes)

rank_input = len(infer_type(inputs[0]).checked_type.shape)
num_new_axis = int(infer_type(inputs[1]).checked_type.shape[0])
axes = relay.split(inputs[1], num_new_axis).astuple()

result = inputs[0]

# TODO (AndrewZhaoLuo): investigate performance issues with consecutive
Expand Down