[GitHub] [incubator-tvm] cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] operator support: DepthToSpace, SpaceToDepth

2019-11-14 Thread GitBox
cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] 
operator support: DepthToSpace, SpaceToDepth
URL: https://github.com/apache/incubator-tvm/pull/4271#discussion_r346612067
 
 

 ##
 File path: tests/python/frontend/onnx/test_forward.py
 ##
 @@ -77,22 +77,27 @@ def get_tvm_output(graph_def, input_data, target, ctx, 
output_shape=None, output
 return tvm_output.asnumpy()
 
 
-def get_caffe2_output(model, x, dtype='float32'):
-import caffe2.python.onnx.backend
-prepared_backend = caffe2.python.onnx.backend.prepare(model)
-W = {model.graph.input[0].name: x.astype(dtype)}
-c2_out = prepared_backend.run(W)[0]
-return c2_out
+def get_onnxruntime_output(model, x, dtype='float32'):
+import onnxruntime.backend
+rep = onnxruntime.backend.prepare(model, 'CPU')
+x = x.astype(dtype)
+ort_out = rep.run(x)[0]
+return ort_out
 
 
 def verify_onnx_forward_impl(graph_file, data_shape, out_shape):
 dtype = 'float32'
 x = np.random.uniform(size=data_shape)
 model = onnx.load_model(graph_file)
-c2_out = get_caffe2_output(model, x, dtype)
-for target, ctx in ctx_list():
-tvm_out = get_tvm_output(model, x, target, ctx, out_shape, dtype)
-tvm.testing.assert_allclose(c2_out, tvm_out, rtol=1e-5, atol=1e-5)
+try:
+c2_out = get_onnxruntime_output(model, x, dtype)
+except onnx.onnx_cpp2py_export.checker.ValidationError as e:
 
 Review comment:
   Hi @jwfromm 
   
   Sorry for the late reply.
   
   I remove the `try excepts` in the testing case and use the default mode 
argument for now. 


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-tvm] cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] operator support: DepthToSpace, SpaceToDepth

2019-11-11 Thread GitBox
cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] 
operator support: DepthToSpace, SpaceToDepth
URL: https://github.com/apache/incubator-tvm/pull/4271#discussion_r344665963
 
 

 ##
 File path: tests/python/frontend/onnx/test_forward.py
 ##
 @@ -77,22 +77,27 @@ def get_tvm_output(graph_def, input_data, target, ctx, 
output_shape=None, output
 return tvm_output.asnumpy()
 
 
-def get_caffe2_output(model, x, dtype='float32'):
-import caffe2.python.onnx.backend
-prepared_backend = caffe2.python.onnx.backend.prepare(model)
-W = {model.graph.input[0].name: x.astype(dtype)}
-c2_out = prepared_backend.run(W)[0]
-return c2_out
+def get_onnxruntime_output(model, x, dtype='float32'):
+import onnxruntime.backend
+rep = onnxruntime.backend.prepare(model, 'CPU')
+x = x.astype(dtype)
+ort_out = rep.run(x)[0]
+return ort_out
 
 
 def verify_onnx_forward_impl(graph_file, data_shape, out_shape):
 dtype = 'float32'
 x = np.random.uniform(size=data_shape)
 model = onnx.load_model(graph_file)
-c2_out = get_caffe2_output(model, x, dtype)
-for target, ctx in ctx_list():
-tvm_out = get_tvm_output(model, x, target, ctx, out_shape, dtype)
-tvm.testing.assert_allclose(c2_out, tvm_out, rtol=1e-5, atol=1e-5)
+try:
+c2_out = get_onnxruntime_output(model, x, dtype)
+except onnx.onnx_cpp2py_export.checker.ValidationError as e:
 
 Review comment:
   Hi @jwfromm 
   
   Thanks for the prompt reply.
   
   I remove the most part of try excepts but `DepthToSpace` because there is a 
strange issue here:
   
   ```
   onnx.onnx_cpp2py_export.checker.ValidationError: Unrecognized attribute: 
mode for operator DepthToSpace
   
   ==> Context: Bad node spec: input: "x" output: "y" op_type: "DepthToSpace" 
attribute { name: "blocksize" i: 2 type: INT } attribute { name: "mode" s: 
"CRD" type: STRING }
   ```
   
   I check the example from 
[onnx.operator.DepthToSpace](https://github.com/onnx/onnx/blob/master/docs/Operators.md#DepthToSpace)
 document and it has the `mode` attribute for `DepthToSpace`, therefore, I keep 
the try-catch for `DepthToSpace`, currently. 


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-tvm] cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] operator support: DepthToSpace, SpaceToDepth

2019-11-11 Thread GitBox
cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] 
operator support: DepthToSpace, SpaceToDepth
URL: https://github.com/apache/incubator-tvm/pull/4271#discussion_r344665963
 
 

 ##
 File path: tests/python/frontend/onnx/test_forward.py
 ##
 @@ -77,22 +77,27 @@ def get_tvm_output(graph_def, input_data, target, ctx, 
output_shape=None, output
 return tvm_output.asnumpy()
 
 
-def get_caffe2_output(model, x, dtype='float32'):
-import caffe2.python.onnx.backend
-prepared_backend = caffe2.python.onnx.backend.prepare(model)
-W = {model.graph.input[0].name: x.astype(dtype)}
-c2_out = prepared_backend.run(W)[0]
-return c2_out
+def get_onnxruntime_output(model, x, dtype='float32'):
+import onnxruntime.backend
+rep = onnxruntime.backend.prepare(model, 'CPU')
+x = x.astype(dtype)
+ort_out = rep.run(x)[0]
+return ort_out
 
 
 def verify_onnx_forward_impl(graph_file, data_shape, out_shape):
 dtype = 'float32'
 x = np.random.uniform(size=data_shape)
 model = onnx.load_model(graph_file)
-c2_out = get_caffe2_output(model, x, dtype)
-for target, ctx in ctx_list():
-tvm_out = get_tvm_output(model, x, target, ctx, out_shape, dtype)
-tvm.testing.assert_allclose(c2_out, tvm_out, rtol=1e-5, atol=1e-5)
+try:
+c2_out = get_onnxruntime_output(model, x, dtype)
+except onnx.onnx_cpp2py_export.checker.ValidationError as e:
 
 Review comment:
   Hi @jwfromm 
   
   Thanks for the prompt reply.
   
   I remove the most part of try excepts but `DepthToSpace` because there is a 
strange issue error here:
   
   ```
   onnx.onnx_cpp2py_export.checker.ValidationError: Unrecognized attribute: 
mode for operator DepthToSpace
   
   ==> Context: Bad node spec: input: "x" output: "y" op_type: "DepthToSpace" 
attribute { name: "blocksize" i: 2 type: INT } attribute { name: "mode" s: 
"CRD" type: STRING }
   ```
   
   I check the example from 
[onnx.operator.DepthToSpace](https://github.com/onnx/onnx/blob/master/docs/Operators.md#DepthToSpace)
 document and it has the `mode` attribute for `DepthToSpace`, therefore, I keep 
the try-catch for `DepthToSpace`, currently. 


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-tvm] cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] operator support: DepthToSpace, SpaceToDepth

2019-11-11 Thread GitBox
cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] 
operator support: DepthToSpace, SpaceToDepth
URL: https://github.com/apache/incubator-tvm/pull/4271#discussion_r344612250
 
 

 ##
 File path: tests/python/frontend/onnx/test_forward.py
 ##
 @@ -85,6 +85,13 @@ def get_caffe2_output(model, x, dtype='float32'):
 return c2_out
 
 Review comment:
   Agree and the replacement is done, thanks for suggestion.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-tvm] cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] operator support: DepthToSpace, SpaceToDepth

2019-11-10 Thread GitBox
cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] 
operator support: DepthToSpace, SpaceToDepth
URL: https://github.com/apache/incubator-tvm/pull/4271#discussion_r344558194
 
 

 ##
 File path: tests/python/frontend/onnx/test_forward.py
 ##
 @@ -85,6 +85,13 @@ def get_caffe2_output(model, x, dtype='float32'):
 return c2_out
 
 
+def get_onnxruntime_output(model, x, dtype='float32'):
+import onnxruntime.backend
+rep = onnxruntime.backend.prepare(model, 'CPU')
+ort_out = rep.run(x)[0]
 
 Review comment:
   Thanks for the review and the issue had been updated.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-tvm] cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] operator support: DepthToSpace, SpaceToDepth

2019-11-08 Thread GitBox
cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] 
operator support: DepthToSpace, SpaceToDepth
URL: https://github.com/apache/incubator-tvm/pull/4271#discussion_r344206710
 
 

 ##
 File path: tests/python/frontend/onnx/test_forward.py
 ##
 @@ -142,6 +142,123 @@ def test_reshape():
 tvm.testing.assert_allclose(ref_shape, tvm_out.shape)
 
 
+def verify_depth_to_space(indata, outdata, mode="DCR"):
+node = onnx.helper.make_node('DepthToSpace',
+ inputs=['x'],
+ outputs=['y'],
+ blocksize=2,
+ mode=mode)
+
+graph = helper.make_graph([node],
+  "depth_to_space_test",
+  inputs=[helper.make_tensor_value_info("x", 
TensorProto.FLOAT, list(indata.shape))],
+  outputs=[helper.make_tensor_value_info("y", 
TensorProto.FLOAT, list(outdata.shape))])
+model = helper.make_model(graph, producer_name='depth_to_space_test')
+
+for target, ctx in ctx_list():
+tvm_out = get_tvm_output(model, [indata], target, ctx, outdata.shape, 
'float32')
+
+tvm.testing.assert_allclose(outdata, tvm_out)
+
+
+def test_depth_to_space():
+# CRD mode
+# (1, 8, 2, 3) input tensor
+x = np.array(0., 1., 2.],
 
 Review comment:
   Hi @jwfromm 
   Thanks for the suggestion and I removed the hardcoded part.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-tvm] cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] operator support: DepthToSpace, SpaceToDepth

2019-11-08 Thread GitBox
cchung100m commented on a change in pull request #4271: [Relay][Frontend][ONNX] 
operator support: DepthToSpace, SpaceToDepth
URL: https://github.com/apache/incubator-tvm/pull/4271#discussion_r344206403
 
 

 ##
 File path: python/tvm/relay/frontend/onnx.py
 ##
 @@ -466,6 +466,76 @@ def _impl_v5(cls, inputs, attr, params):
 static_shape.asnumpy().astype('int32')))
 return out
 
+
+class DepthToSpace(OnnxOpConverter):
+""" Operator converter for DepthToSpace.
+"""
+
+@classmethod
+def _impl_v1(cls, inputs, attr, params):
 
 Review comment:
   Hi @jwfromm 
   Thanks for the review and the issue had been updated.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services