Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ class Flatten(OnnxOpConverter):
@classmethod
def _impl_v1(cls, inputs, attr, params):
axis = attr.get("axis", 1)
ishape = _op.shape_of(inputs[0])
ishape = shape_of(inputs[0])
ndim = infer_shape(ishape)[0]
if axis < 0:
axis = axis + ndim
Expand All @@ -1148,7 +1148,7 @@ def _impl_v1(cls, inputs, attr, params):
else:
pre_shape = _op.prod(_op.strided_slice(ishape, [0], [axis], [1]), keepdims=True)
post_shape = _op.prod(_op.strided_slice(ishape, [axis], [ndim], [1]), keepdims=True)
newshape = _op.concatenate([pre_shape, post_shape], axis=0)
newshape = fold_constant(_op.concatenate([pre_shape, post_shape], axis=0))
out = _op.reshape(inputs[0], newshape)
return out

Expand Down
25 changes: 12 additions & 13 deletions tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,22 +576,21 @@ def test_squeeze(target, dev):

@tvm.testing.parametrize_targets
def test_flatten(target, dev):
def verify_flatten(in_shape, axis, ref_shape):
flatten_node = helper.make_node("Flatten", ["in"], ["out"], axis=axis)

in_shape = (1, 3, 4, 4)
axis = 1
ref_shape = (1, 48)

flatten_node = helper.make_node("Flatten", ["in"], ["out"], axis=axis)
graph = helper.make_graph(
[flatten_node],
"flatten_test",
inputs=[helper.make_tensor_value_info("in", TensorProto.FLOAT, list(in_shape))],
outputs=[helper.make_tensor_value_info("out", TensorProto.FLOAT, list(ref_shape))],
)

graph = helper.make_graph(
[flatten_node],
"flatten_test",
inputs=[helper.make_tensor_value_info("in", TensorProto.FLOAT, list(in_shape))],
outputs=[helper.make_tensor_value_info("out", TensorProto.FLOAT, list(ref_shape))],
)
model = helper.make_model(graph, producer_name="flatten_test")
verify_with_ort(model, [in_shape], target=target, dev=dev)

model = helper.make_model(graph, producer_name="flatten_test")
verify_with_ort(model, [in_shape], target=target, dev=dev)
verify_flatten((1, 3, 4, 4), 1, (1, 48))
verify_flatten((1,), 1, (1, 1))


@tvm.testing.parametrize_targets
Expand Down