zhreshold commented on a change in pull request #12731: [MXNET-892] ONNX
export/import: DepthToSpace, SpaceToDepth operators
URL: https://github.com/apache/incubator-mxnet/pull/12731#discussion_r225726697
##########
File path: python/mxnet/contrib/onnx/mx2onnx/_op_translations.py
##########
@@ -2077,3 +2077,53 @@ def convert_sqrt(node, **kwargs):
name=name,
)
return [node]
+
+@mx_op.register("depth_to_space")
+def convert_depthtospace(node, **kwargs):
+ """Map MXNet's depth_to_space operator attributes to onnx's
+ DepthToSpace operator and return the created node.
+ """
+ onnx = import_onnx_modules()
+ name = node["name"]
+ proc_nodes = kwargs["proc_nodes"]
+ inputs = node["inputs"]
+ attrs = node["attrs"]
+
+ input_node_id = kwargs["index_lookup"][inputs[0][0]]
+ input_node = proc_nodes[input_node_id].name
+
+ blksize = int(attrs.get("block_size", 0))
+
+ node = onnx.helper.make_node(
+ "DepthToSpace",
+ [input_node],
+ [name],
+ blocksize=blksize,
+ name=name,
+ )
+ return [node]
+
+@mx_op.register("space_to_depth")
+def convert_spacetodepth(node, **kwargs):
+ """Map MXNet's space_to_depth operator attributes to onnx's
+ SpaceToDepth operator and return the created node.
+ """
+ onnx = import_onnx_modules()
Review comment:
can you try to modularize line 2111 to 2115, which is duplicated in every op
converter, e.g., 2086-2090. You may not complete it in this PR, but I think
it's a good practice to remove manual repetitive work.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services