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

Frontend: add onnx GlobalLpPool op #8845

Merged
merged 3 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions python/tvm/relay/frontend/onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,18 @@ def _impl_v1(cls, inputs, attr, params):
return _op.power(out, reci_p)


class GlobalLpPool(OnnxOpConverter):
"""Operator converter for GlobalLpPool."""

@classmethod
def _impl_v1(cls, inputs, attr, params):
in_shape = infer_shape(inputs[0])
assert len(in_shape) >= 4, "input shape support NCHW or NCDHW"
mbrookhart marked this conversation as resolved.
Show resolved Hide resolved
attr["kernel_shape"] = in_shape[2:]
mbrookhart marked this conversation as resolved.
Show resolved Hide resolved

return LpPool._impl_v1(inputs, attr, params)


class Mul(Elemwise):
"""Operator converter for Multiply."""

Expand Down Expand Up @@ -3578,6 +3590,7 @@ def _get_convert_map(opset):
# defs/nn
"AveragePool": AveragePool.get_converter(opset),
"LpPool": LpPool.get_converter(opset),
"GlobalLpPool": GlobalLpPool.get_converter(opset),
"MaxPool": MaxPool.get_converter(opset),
"MaxUnpool": MaxUnpool.get_converter(opset),
"Conv": Conv.get_converter(opset),
Expand Down
45 changes: 45 additions & 0 deletions tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,50 @@ def verify_lppool(x_shape, kernel_shape, p, strides, pads, out_shape, auto_pad="
)


def verify_global_lppool(x_shape, p, out_shape):
pool_node = helper.make_node(
"GlobalLpPool",
inputs=["x"],
outputs=["y"],
p=p,
)

graph = helper.make_graph(
[pool_node],
"global_lppool_test",
inputs=[helper.make_tensor_value_info("x", TensorProto.FLOAT, list(x_shape))],
outputs=[helper.make_tensor_value_info("y", TensorProto.FLOAT, list(out_shape))],
)

model = helper.make_model(graph, producer_name="global_lppool_test")
verify_with_ort(model, [x_shape], out_shape)
mbrookhart marked this conversation as resolved.
Show resolved Hide resolved


@tvm.testing.uses_gpu
def test_global_lppool():

# Pool2D
verify_global_lppool(
x_shape=[1, 15, 32, 32],
p=2,
out_shape=[1, 15, 1, 1],
)

# Pool2D
verify_global_lppool(
x_shape=[1, 15, 32, 32],
p=3,
out_shape=[1, 15, 1, 1],
)

# Pool3D
verify_global_lppool(
x_shape=[1, 15, 3, 32, 32],
p=2,
out_shape=[1, 15, 1, 1, 1],
)


def verify_rnn(
seq_length,
batch_size,
Expand Down Expand Up @@ -5644,3 +5688,4 @@ def repeat(N, D):
test_random_uniform()
test_convinteger()
test_batch_matmul()
test_global_lppool()