You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/04/18 11:51:17 UTC

[GitHub] [tvm] ah-cheng opened a new pull request, #11034: [Frontend][ONNX]support Pool2D layout is CHW

ah-cheng opened a new pull request, #11034:
URL: https://github.com/apache/tvm/pull/11034

   Hi, my onnx model is superpoint. it`s converted  from a pytorch model.
   When I import the model. I get the relay as follow:
   `
   ...
   %38 = transpose(%37, axes=[0, 1, 3, 2, 4]);
   %39 = reshape(%38, newshape=[1, 480, 640]);
   %40 = nn.max_pool2d(%39, pool_size=[9, 9], padding=[4, 4, 4, 4], layout="NCW");
   %41 = equal(%39, %40);
   cast(%41, dtype="float32")
   `
   The model layer in Netron is:
   ![image](https://user-images.githubusercontent.com/50271153/163803337-e9cb51ff-363b-4533-915e-5a6d7d39701e.png)
   Then we can see the %39 reshape is a 3 dimensions. It is legal in pytorch model. But in ONNX, I will get a error.
   Then I will add a `expand_dims` before pool2D and a squeeze after pool2D like the code I commited.
   
   But i don`t know how to add a unit test case. because there will be error in onnxruntime if the pool2D  shape is 3D.
   ![image](https://user-images.githubusercontent.com/50271153/163803954-d1987128-f4dd-4ce4-96ad-2a04842b5ed6.png)
   
   cc: @MatthewARM @jwfromm @AndrewZhaoLuo 
   
   
   
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] AndrewZhaoLuo commented on a diff in pull request #11034: [Frontend][ONNX]support Pool2D layout is CHW

Posted by GitBox <gi...@apache.org>.
AndrewZhaoLuo commented on code in PR #11034:
URL: https://github.com/apache/tvm/pull/11034#discussion_r853331557


##########
python/tvm/relay/frontend/onnx.py:
##########
@@ -410,8 +410,16 @@ class Pool(OnnxOpConverter):
 
     @classmethod
     def _impl_v1(cls, inputs, attr, params):
+        data = inputs[0]
+        input_shape = infer_shape(data)
+        ndim = len(input_shape)
+
         attr_cvt, data = cls._run_calculation(inputs, attr, params)
-        return attr_cvt([data], attr, params)
+        out = attr_cvt([data], attr, params)
+
+        if ndim == 3 and len(attr["kernel_shape"]) == 2:

Review Comment:
   Can you make this so if kernel_shape rank and ndim differ by 1 we assume it's missing a batch dimension and runs below code? (same thing for `_run_calculation`)



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] AndrewZhaoLuo merged pull request #11034: [Frontend][ONNX]support Pool2D layout is CHW

Posted by GitBox <gi...@apache.org>.
AndrewZhaoLuo merged PR #11034:
URL: https://github.com/apache/tvm/pull/11034


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] ah-cheng commented on pull request #11034: [Frontend][ONNX]support Pool2D layout is CHW

Posted by GitBox <gi...@apache.org>.
ah-cheng commented on PR #11034:
URL: https://github.com/apache/tvm/pull/11034#issuecomment-1103355935

   ok, thanks @AndrewZhaoLuo  
   I have made the modifications as you said, and run it successed again.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] AndrewZhaoLuo commented on a diff in pull request #11034: [Frontend][ONNX]support Pool2D layout is CHW

Posted by GitBox <gi...@apache.org>.
AndrewZhaoLuo commented on code in PR #11034:
URL: https://github.com/apache/tvm/pull/11034#discussion_r853331557


##########
python/tvm/relay/frontend/onnx.py:
##########
@@ -410,8 +410,16 @@ class Pool(OnnxOpConverter):
 
     @classmethod
     def _impl_v1(cls, inputs, attr, params):
+        data = inputs[0]
+        input_shape = infer_shape(data)
+        ndim = len(input_shape)
+
         attr_cvt, data = cls._run_calculation(inputs, attr, params)
-        return attr_cvt([data], attr, params)
+        out = attr_cvt([data], attr, params)
+
+        if ndim == 3 and len(attr["kernel_shape"]) == 2:

Review Comment:
   Can you make this so if kernel_shape rank and ndim differ by 1 we assume it's missing a batch dimension and runs below code? (same thing for _run_calculation



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org