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][MXNet] Support mode=instance,spatial for l2_normalize #7062

Merged
merged 1 commit into from
Dec 24, 2020
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
13 changes: 10 additions & 3 deletions python/tvm/relay/frontend/mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,12 +1091,19 @@ def _mx_box_decode(inputs, attrs):
def _mx_l2_normalize(inputs, attrs):
new_attrs = {}
mode = attrs.get_str("mode", "instance")
if mode != "channel":
if mode == "channel":
new_attrs["axis"] = [1]
elif mode == "instance":
ndim = len(_infer_type(inputs[0]).checked_type.shape)
new_attrs["axis"] = list(range(1, ndim))
elif mode == "spatial":
ndim = len(_infer_type(inputs[0]).checked_type.shape)
new_attrs["axis"] = list(range(2, ndim))
else:
raise tvm.error.OpAttributeInvalid(
'Value of attribute "mode" must equal "channel" for operator l2_normalize.'
'Mode "{}" is not supported for operator l2_normalize.'.format(mode)
)
new_attrs["eps"] = attrs.get_float("eps", 1e-10)
new_attrs["axis"] = [1]
return _op.nn.l2_normalize(inputs[0], **new_attrs)


Expand Down
6 changes: 6 additions & 0 deletions tests/python/frontend/mxnet/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,12 @@ def test_forward_l2_normalize():
mx_sym = mx.sym.L2Normalization(data, mode="channel")
verify_mxnet_frontend_impl(mx_sym, (2, 3, 4, 5), (2, 3, 4, 5))

mx_sym = mx.sym.L2Normalization(data, mode="instance")
verify_mxnet_frontend_impl(mx_sym, (2, 3, 4, 5), (2, 3, 4, 5))

mx_sym = mx.sym.L2Normalization(data, mode="spatial")
verify_mxnet_frontend_impl(mx_sym, (2, 3, 4, 5), (2, 3, 4, 5))


@tvm.testing.uses_gpu
def test_forward_logistic_regression_output():
Expand Down