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 2020/09/01 22:02:05 UTC

[GitHub] [incubator-tvm] Laurawly opened a new pull request #6373: Add shape functions

Laurawly opened a new pull request #6373:
URL: https://github.com/apache/incubator-tvm/pull/6373


   Added shape functions for image.resize, image.grid_sample and image.affine_grid
   
   @icemelon9 Could you please review?


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] zhiics commented on a change in pull request #6373: Register shape functions for some image related ops

Posted by GitBox <gi...@apache.org>.
zhiics commented on a change in pull request #6373:
URL: https://github.com/apache/incubator-tvm/pull/6373#discussion_r513786300



##########
File path: tests/python/relay/test_any.py
##########
@@ -891,6 +891,87 @@ def test_any_ndarray_size():
     verify_any_ndarray_size((2, 2))
     verify_any_ndarray_size((1, 2, 3, 4))
 
+def verify_any_resize(data_shape, scale, layout, static_data_shape, ref_out_shape):
+    mod = tvm.IRModule()
+    dtype = "float32"
+    data = relay.var('data', shape=data_shape, dtype=dtype)
+    if layout == "NHWC":
+        size = (data_shape[1] * scale, data_shape[2] * scale)
+    else:
+        size = (data_shape[2] * scale, data_shape[3] * scale)
+    y = relay.image.resize(data, size, layout)
+    mod["main"] = relay.Function([data], y)
+    data_np = np.random.uniform(size=static_data_shape).astype(dtype)
+    for kind in ["debug", "vm"]:

Review comment:
       BTW, this has been moved to `test_result` and you may want to annotate the test with `@tvm.testing.uses_gpu` if gpu is supported 




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] Laurawly commented on a change in pull request #6373: Register shape functions for some image related ops

Posted by GitBox <gi...@apache.org>.
Laurawly commented on a change in pull request #6373:
URL: https://github.com/apache/incubator-tvm/pull/6373#discussion_r513774407



##########
File path: python/tvm/relay/op/image/_image.py
##########
@@ -118,3 +162,19 @@ def compute_grid_sample(attrs, inputs, out_dtype):
     return [topi.image.grid_sample(inputs[0], inputs[1], method, layout)]
 
 reg.register_injective_schedule("image.grid_sample")
+
+@script
+def _grid_sample_func(data, grid):
+    out = output_tensor((4,), "int64")
+    out[0] = int64(data[0])
+    out[1] = int64(data[1])
+    out[2] = int64(grid[2])
+    out[3] = int64(grid[3])

Review comment:
       No, I think it only supports NCHW




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] Laurawly merged pull request #6373: Register shape functions for some image related ops

Posted by GitBox <gi...@apache.org>.
Laurawly merged pull request #6373:
URL: https://github.com/apache/incubator-tvm/pull/6373


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on pull request #6373: Register shape functions for some image related ops

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #6373:
URL: https://github.com/apache/incubator-tvm/pull/6373#issuecomment-718216131


   ping @Laurawly @icemelon9 please follow up


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] Laurawly commented on a change in pull request #6373: Register shape functions for some image related ops

Posted by GitBox <gi...@apache.org>.
Laurawly commented on a change in pull request #6373:
URL: https://github.com/apache/incubator-tvm/pull/6373#discussion_r513774175



##########
File path: python/tvm/relay/op/image/_image.py
##########
@@ -109,6 +136,23 @@ def compute_affine_grid(attrs, inputs, out_dtype):
 
 reg.register_injective_schedule("image.affine_grid")
 
+@script
+def _affine_grid_func(data, target_shape):
+    out = output_tensor((4,), "int64")
+    out[0] = int64(data[0])
+    out[1] = int64(2)
+    out[2] = int64(target_shape[0])

Review comment:
       No I don't think so.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] icemelon9 commented on a change in pull request #6373: Register shape functions for some image related ops

Posted by GitBox <gi...@apache.org>.
icemelon9 commented on a change in pull request #6373:
URL: https://github.com/apache/incubator-tvm/pull/6373#discussion_r495102806



##########
File path: python/tvm/relay/op/image/_image.py
##########
@@ -40,6 +40,33 @@ def compute_resize(attrs, inputs, out_type):
 
 reg.register_injective_schedule("image.resize")
 
+@script
+def _resize_func(image_shape, size, height_axis, width_axis, channel_axis):

Review comment:
       change the name to `_resize_shape_func`.

##########
File path: python/tvm/relay/op/image/_image.py
##########
@@ -118,3 +162,19 @@ def compute_grid_sample(attrs, inputs, out_dtype):
     return [topi.image.grid_sample(inputs[0], inputs[1], method, layout)]
 
 reg.register_injective_schedule("image.grid_sample")
+
+@script
+def _grid_sample_func(data, grid):
+    out = output_tensor((4,), "int64")
+    out[0] = int64(data[0])
+    out[1] = int64(data[1])
+    out[2] = int64(grid[2])
+    out[3] = int64(grid[3])

Review comment:
       same question here. different layout?

##########
File path: python/tvm/relay/op/image/_image.py
##########
@@ -40,6 +40,33 @@ def compute_resize(attrs, inputs, out_type):
 
 reg.register_injective_schedule("image.resize")
 
+@script
+def _resize_func(image_shape, size, height_axis, width_axis, channel_axis):
+    out = output_tensor((4,), "int64")
+    out[0] = int64(image_shape[0])
+    out[height_axis] = int64(size[0])
+    out[width_axis] = int64(size[1])
+    out[channel_axis] = image_shape[channel_axis]
+    return out
+
+@reg.register_shape_func("image.resize", False)
+def resize_func(attrs, inputs, _):

Review comment:
       change the name to `resize_shape_func`

##########
File path: python/tvm/relay/op/image/_image.py
##########
@@ -40,6 +40,33 @@ def compute_resize(attrs, inputs, out_type):
 
 reg.register_injective_schedule("image.resize")
 
+@script
+def _resize_func(image_shape, size, height_axis, width_axis, channel_axis):
+    out = output_tensor((4,), "int64")
+    out[0] = int64(image_shape[0])
+    out[height_axis] = int64(size[0])
+    out[width_axis] = int64(size[1])
+    out[channel_axis] = image_shape[channel_axis]
+    return out
+
+@reg.register_shape_func("image.resize", False)
+def resize_func(attrs, inputs, _):
+    """
+    Shape function for resize op.
+    """
+    layout = attrs.layout
+    height_axis = width_axis = channel_axis = 1
+    for i, letter in enumerate(layout):
+        if letter == "H":
+            height_axis = i
+        if letter == "W":
+            width_axis = i
+        if letter == "C":
+            channel_axis = i
+    size = get_const_tuple(attrs.size)
+    return [_resize_func(inputs[0], convert(size), convert(height_axis),

Review comment:
       Could you also provide batch axis to the shape func as well?

##########
File path: python/tvm/relay/op/image/_image.py
##########
@@ -109,6 +136,23 @@ def compute_affine_grid(attrs, inputs, out_dtype):
 
 reg.register_injective_schedule("image.affine_grid")
 
+@script
+def _affine_grid_func(data, target_shape):
+    out = output_tensor((4,), "int64")
+    out[0] = int64(data[0])
+    out[1] = int64(2)
+    out[2] = int64(target_shape[0])

Review comment:
       do we support different layout for `affine_grid`?




----------------------------------------------------------------
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:
users@infra.apache.org