icemelon9 commented on a change in pull request #5955:
URL: https://github.com/apache/incubator-tvm/pull/5955#discussion_r459019580



##########
File path: tests/python/relay/test_any.py
##########
@@ -816,6 +816,66 @@ def test_mixed_input_type():
         assert result.asnumpy().shape == ref_out_shape, \
             "Shape mismatch: expect %s but got %s." % (str(ref_out_shape), 
str(result.asnumpy().shape))
 
+def verify_any_crop_and_resize(data_shape, boxes_shape, box_indices_shape, 
crop_size, 
+                               layout, static_boxes, static_box_indices_shape, 
ref_out_shape):
+    mod = tvm.IRModule()
+    dtype = "float32"
+    indices_dtype = "int32"
+    data = relay.var('data', shape=data_shape, dtype=dtype)
+    boxes = relay.var('boxes', shape=boxes_shape, dtype=dtype)
+    box_indices = relay.var('box_indices', shape=box_indices_shape, 
dtype=indices_dtype)
+    y = relay.image.crop_and_resize(data, boxes, box_indices, crop_size, 
layout)
+    mod["main"] = relay.Function([data, boxes, box_indices], y)
+    data_np = np.random.uniform(size=data_shape).astype(dtype)
+    boxes_np = np.random.uniform(size=static_boxes).astype(dtype)
+    box_indices_np = 
np.random.uniform(size=static_box_indices_shape).astype(indices_dtype)    
+    for kind in ["debug", "vm"]:
+        ex = relay.create_executor(kind, mod=mod, ctx=tvm.cpu(), target="llvm")
+        result = ex.evaluate()(data_np, boxes_np, box_indices_np)
+        assert result.asnumpy().shape == ref_out_shape, \
+            "Shape mismatch: expect %s but got %s." % (str(ref_out_shape), 
str(result.asnumpy().shape))
+
+def test_any_crop_and_resize():
+    verify_any_crop_and_resize(
+        data_shape=(1, 234, 234, 256), 
+        boxes_shape=(relay.Any(), 4), 
+        box_indices_shape=(relay.Any(),),
+        crop_size=(14, 14),
+        layout='NHWC',
+        static_boxes=(128, 4),
+        static_box_indices_shape=(128,),
+        ref_out_shape=(128, 14, 14, 256))
+    verify_any_crop_and_resize(
+        data_shape=(1, 256, 234, 234), 
+        boxes_shape=(relay.Any(), 4), 
+        box_indices_shape=(relay.Any(),),
+        crop_size=(14, 14),
+        layout='NCHW',
+        static_boxes=(128, 4),
+        static_box_indices_shape=(128,),
+        ref_out_shape=(128, 256, 14, 14)
+        )
+
+def verify_any_mirror_pad(data_shape, pad_width, static_data_shape, 
ref_out_shape):
+    mod = tvm.IRModule()
+    dtype = "float32"
+    data = relay.var('data', shape=data_shape, dtype=dtype)
+    y = relay.nn.mirror_pad(data, pad_width)
+    mod["main"] = relay.Function([data], y)
+    data_np = np.random.uniform(size=static_data_shape).astype(dtype)
+    for kind in ["debug", "vm"]:
+        ex = relay.create_executor(kind, mod=mod, ctx=tvm.cpu(), target="llvm")
+        result = ex.evaluate()(data_np)
+        assert result.asnumpy().shape == ref_out_shape, \

Review comment:
       use `tvm.testing.assert_allclose`.
   
   

##########
File path: tests/python/relay/test_any.py
##########
@@ -816,6 +816,66 @@ def test_mixed_input_type():
         assert result.asnumpy().shape == ref_out_shape, \
             "Shape mismatch: expect %s but got %s." % (str(ref_out_shape), 
str(result.asnumpy().shape))
 
+def verify_any_crop_and_resize(data_shape, boxes_shape, box_indices_shape, 
crop_size, 
+                               layout, static_boxes, static_box_indices_shape, 
ref_out_shape):
+    mod = tvm.IRModule()
+    dtype = "float32"
+    indices_dtype = "int32"
+    data = relay.var('data', shape=data_shape, dtype=dtype)
+    boxes = relay.var('boxes', shape=boxes_shape, dtype=dtype)
+    box_indices = relay.var('box_indices', shape=box_indices_shape, 
dtype=indices_dtype)
+    y = relay.image.crop_and_resize(data, boxes, box_indices, crop_size, 
layout)
+    mod["main"] = relay.Function([data, boxes, box_indices], y)
+    data_np = np.random.uniform(size=data_shape).astype(dtype)
+    boxes_np = np.random.uniform(size=static_boxes).astype(dtype)
+    box_indices_np = 
np.random.uniform(size=static_box_indices_shape).astype(indices_dtype)    
+    for kind in ["debug", "vm"]:
+        ex = relay.create_executor(kind, mod=mod, ctx=tvm.cpu(), target="llvm")
+        result = ex.evaluate()(data_np, boxes_np, box_indices_np)
+        assert result.asnumpy().shape == ref_out_shape, \

Review comment:
       use `tvm.testing.assert_allclose`. it will check both the shape and value




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