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

[ONNX] Update Slice op conversion to take strides into account, clean up tests #6467

Merged
merged 13 commits into from
Sep 13, 2020
26 changes: 20 additions & 6 deletions python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,9 @@ def _impl_v10(cls, inputs, attr, params):
attrs = {"starts": inputs[1], "ends": inputs[2]}
if len(inputs) >= 4:
attrs["axes"] = inputs[3]
if len(inputs) >= 5:
attrs["steps"] = inputs[4]

attrs = {k: (v, get_name(v)) for (k, v) in attrs.items()}
attrs = {
k: params[v[1]].asnumpy()
Expand All @@ -1033,12 +1036,23 @@ def _impl_v10(cls, inputs, attr, params):
}

# Update the starts and ends according to axes if required.
if "axes" in attrs:
if max(attrs["axes"] + 1) != len(attrs["axes"]):
new_starts, new_ends, _ = cls._common(attrs["starts"], attrs["ends"], attrs["axes"])
attrs["starts"] = new_starts
attrs["ends"] = new_ends
return _op.strided_slice(inputs[0], begin=list(attrs["starts"]), end=list(attrs["ends"]))
if "axes" in attrs and max(attrs["axes"] + 1) != len(attrs["axes"]):
new_starts, new_ends, _ = cls._common(attrs["starts"], attrs["ends"], attrs["axes"])
attrs["starts"] = new_starts
attrs["ends"] = new_ends

begins = list(attrs["starts"])
ends = list(attrs["ends"])
strides = [1] * len(begins)

if "steps" in attrs:
steps = list(attrs["steps"])
axes = attrs["axes"]
assert len(steps) == len(axes)
for axis, step in zip(axes, steps):
strides[axis] = step

return _op.strided_slice(inputs[0], begin=begins, end=ends, strides=strides)


class Gather(OnnxOpConverter):
Expand Down
Loading