masahi commented on a change in pull request #7883:
URL: https://github.com/apache/tvm/pull/7883#discussion_r616257175



##########
File path: python/tvm/topi/image/resize.py
##########
@@ -59,6 +59,33 @@ def get_2d_pixel(data, layout, boxes, image_height, 
image_width, n, c, y, x, cc,
     return data(n, c, y, x, cc).astype("float")
 
 
+def get_iny_inx(
+    y, x, image_height, image_width, target_height, target_width, 
coordinate_transformation_mode
+):
+    scale_y = te.div(image_height.astype("float"), 
target_height.astype("float"))
+    scale_x = te.div(image_width.astype("float"), target_width.astype("float"))
+    if coordinate_transformation_mode == "half_pixel":
+        in_y = (y + 0.5) * scale_y - 0.5
+        in_x = (x + 0.5) * scale_x - 0.5
+    elif coordinate_transformation_mode == "align_corners":
+        in_y = y * (image_height - 1).astype("float") / (target_height - 1)
+        in_x = x * (image_width - 1).astype("float") / (target_width - 1)
+    elif coordinate_transformation_mode == "asymmetric":
+        in_y = y * scale_y
+        in_x = x * scale_x
+    elif coordinate_transformation_mode == "pytorch_half_pixel":

Review comment:
       Also when I added `half_pixel` option, I intended this option to 
correspond exactly to ONNX `pytorch_half_pixel`. In PT ONNX exporter, 
`pytorch_half_pixel` is introduced for bilinear + align_corners=False case, and 
that is also when `half_pixel` is used in our PT frontend. See 
https://github.com/pytorch/pytorch/blob/c371542efc31b1abfe6f388042aa3ab0cef935f2/torch/onnx/symbolic_helper.py#L517-L518
   
   So we probably don't need ``pytorch_half_pixel`. We can update `half_pixel` 
if necessary.




-- 
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:
[email protected]


Reply via email to