@@ -306,6 +306,72 @@ def verify_roi_align(data_shape, rois_shape, pooled_size, spatial_scale, sample_
306
306
verify_roi_align ((4 , 4 , 16 , 16 ), (32 , 5 ), pooled_size = 7 , spatial_scale = 0.5 , sample_ratio = 2 )
307
307
308
308
309
+ def test_proposal ():
310
+ def verify_proposal (np_cls_prob , np_bbox_pred , np_im_info , np_out , attrs ):
311
+ cls_prob = relay .var ("cls_prob" , relay .ty .TensorType (np_cls_prob .shape , "float32" ))
312
+ bbox_pred = relay .var ("bbox_pred" , relay .ty .TensorType (np_bbox_pred .shape , "float32" ))
313
+ im_info = relay .var ("im_info" , relay .ty .TensorType (np_im_info .shape , "float32" ))
314
+ z = relay .vision .proposal (cls_prob , bbox_pred , im_info , ** attrs )
315
+ zz = relay .ir_pass .infer_type (z )
316
+
317
+ assert zz .checked_type == relay .ty .TensorType (np_out .shape , "float32" )
318
+
319
+ func = relay .Function ([cls_prob , bbox_pred , im_info ], z )
320
+ func = relay .ir_pass .infer_type (func )
321
+ for target in ['cuda' ]:
322
+ if not tvm .module .enabled (target ):
323
+ print ("Skip test because %s is not enabled." % target )
324
+ continue
325
+ ctx = tvm .context (target , 0 )
326
+ intrp1 = relay .create_executor ("graph" , ctx = ctx , target = target )
327
+ op_res1 = intrp1 .evaluate (func )(np_cls_prob , np_bbox_pred , np_im_info )
328
+ tvm .testing .assert_allclose (op_res1 .asnumpy (), np_out , rtol = 1e-4 )
329
+ intrp2 = relay .create_executor ("debug" , ctx = ctx , target = target )
330
+ op_res2 = intrp2 .evaluate (func )(np_cls_prob , np_bbox_pred , np_im_info )
331
+ tvm .testing .assert_allclose (op_res2 .asnumpy (), np_out , rtol = 1e-4 )
332
+
333
+ attrs = {
334
+ 'scales' : (0.5 ,),
335
+ 'ratios' : (0.5 ,),
336
+ 'feature_stride' : 16 ,
337
+ 'iou_loss' : False ,
338
+ 'rpn_min_size' : 16 ,
339
+ 'threshold' : 0.7 ,
340
+ 'rpn_pre_nms_top_n' : 200 ,
341
+ 'rpn_post_nms_top_n' : 4 ,
342
+ }
343
+
344
+ np_cls_prob = np .array ([[
345
+ [[0.3 , 0.6 , 0.2 ], [0.4 , 0.7 , 0.5 ], [0.1 , 0.4 , 0.3 ]],
346
+ [[0.7 , 0.5 , 0.3 ], [0.6 , 0.4 , 0.8 ], [0.9 , 0.2 , 0.5 ]]
347
+ ]], dtype = 'float32' )
348
+ np_bbox_pred = np .array ([[
349
+ [[0.5 , 1.0 , 0.6 ], [0.8 , 1.2 , 2.0 ], [0.9 , 1.0 , 0.8 ]],
350
+ [[0.5 , 1.0 , 0.7 ], [0.8 , 1.2 , 1.6 ], [2.1 , 1.5 , 0.7 ]],
351
+ [[1.0 , 0.5 , 0.7 ], [1.5 , 0.9 , 1.6 ], [1.4 , 1.5 , 0.8 ]],
352
+ [[1.0 , 0.5 , 0.6 ], [1.5 , 0.9 , 2.0 ], [1.8 , 1.0 , 0.9 ]],
353
+ ]], dtype = 'float32' )
354
+ np_im_info = np .array ([[48. , 48. , 1. ]], dtype = 'float32' )
355
+ np_out = np .array ([
356
+ [0. , 0. , 2.8451548 ,28.38012 , 18.154846 ],
357
+ [0. , 0. , 15.354933 , 41.96971 , 41.245064 ],
358
+ [0. , 18.019852 , 1.0538368 , 51.98015 , 25.946163 ],
359
+ [0. , 27.320923 , - 1.266357 , 55. , 24.666357 ]
360
+ ], dtype = 'float32' )
361
+
362
+
363
+ verify_proposal (np_cls_prob , np_bbox_pred , np_im_info , np_out , attrs )
364
+
365
+ np_out = np .array ([
366
+ [ 0. , - 5.25 , - 2.5 , 21.75 , 19. ],
367
+ [ 0. , 11.25 , - 2. , 37.25 , 18.5 ],
368
+ [ 0. , 26.849998 , - 2.3000002 , 53.45 , 18.6 ],
369
+ [ 0. , - 4.95 , 13.799999 , 22.25 , 35.5 ]
370
+ ], dtype = 'float32' )
371
+ attrs ['iou_loss' ] = True
372
+ verify_proposal (np_cls_prob , np_bbox_pred , np_im_info , np_out , attrs )
373
+
374
+
309
375
def test_yolo_reorg_infer_shape ():
310
376
def verify_yolo_reorg (shape , stride , out_shape ):
311
377
x = relay .var ("x" , relay .TensorType (shape , "float32" ))
@@ -347,5 +413,6 @@ def verify_yolo_reorg(shape, stride):
347
413
test_multibox_transform_loc ()
348
414
test_nms ()
349
415
test_roi_align ()
416
+ test_proposal ()
350
417
test_yolo_reorg_infer_shape ()
351
418
test_yolo_reorg ()
0 commit comments