marcoabreu commented on a change in pull request #16341: [WIP][New Op] Add 
deformable conv v2
URL: https://github.com/apache/incubator-mxnet/pull/16341#discussion_r330663090
 
 

 ##########
 File path: tests/python/unittest/test_contrib_operator.py
 ##########
 @@ -333,6 +334,46 @@ def test_multibox_prior_op():
     boxes = Y.reshape((h, w, 5, 4))
     assert_allclose(boxes.asnumpy()[250, 250, 0, :], np.array([-0.948249,  
0.362671,  1.636436,  0.530377]), atol=1e-5, rtol=1e-5)
 
+@with_seed()
+def test_modulated_deformable_convolution():
+    for num_batch in [1, 2]:
+        for num_channel_data, num_deformable_group in itertools.product([4, 
8], [1, 2]):
+            for input_height, input_width in itertools.product([5, 6], [5, 6]):
+                for dilate in [(1, 1), (2, 2)]:
+                    for grad_nodes in [['im_data'], ['offset_data'], 
['weight']]:
+                        output_height = input_height
+                        output_width = input_width
+                        im_data = np.random.rand(num_batch, num_channel_data, 
input_height, input_width)
+                        offset_data = \
+                            np.random.rand(num_batch, num_deformable_group * 3 
* 3 * 2, output_height, output_width)\
+                            * 0.8 + 0.1
+                        mask_data = np.random.rand(num_batch, 
num_deformable_group * 3 * 3, output_height, output_width)
+                        mask_data = 0.5 * (1 + np.tanh(0.5 * mask_data)) # 
sigmoid
+                        weight = np.random.normal(0, 0.001, (num_channel_data, 
num_channel_data, 3, 3))
+                        bias = np.zeros(num_channel_data)
+
+                        im_data_var = mx.symbol.Variable(name="im_data")
+                        offset_data_var = 
mx.symbol.Variable(name="offset_data")
+                        mask_data_var = mx.symbol.Variable(name="mask_data")
+                        weight_var = mx.symbol.Variable(name="weight")
+                        bias_var = mx.symbol.Variable(name="bias")
+                        op = 
mx.sym.contrib.ModulatedDeformableConvolution(name='test_op', data=im_data_var,
+                                                                           
offset=offset_data_var, mask=mask_data_var,
+                                                                           
weight=weight_var, bias=bias_var,
+                                                                           
num_filter=num_channel_data, pad=dilate,
+                                                                           
kernel=(3, 3), stride=(1, 1), dilate=dilate,
+                                                                           
num_deformable_group=num_deformable_group)
+                        if grad_nodes[0] == 'offset_data':
+                            # wider tolerance needed for coordinate 
differential
+                            rtol, atol = 1.0, 1e-2
+                        else:
+                            rtol, atol = 0.05, 1e-3
+                        # By now we only have gpu implementation
+                        if default_context().device_type == 'gpu':
 
 Review comment:
   Please use conditional test annotations instead of making an exclude inside 
the test. Otherwise, we won't know that it has been skipped.

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

Reply via email to