未验证 提交 f10d26e9 编写于 作者: L Leo Guo 提交者: GitHub

Modify the large case in test_generate_proposals_v2_op to small for kunlun. *test=kunlun (#43587)

上级 bba7c5b9
...@@ -17,6 +17,7 @@ from __future__ import print_function ...@@ -17,6 +17,7 @@ from __future__ import print_function
import unittest import unittest
import numpy as np import numpy as np
import sys import sys
sys.path.append("..") sys.path.append("..")
import math import math
...@@ -48,7 +49,7 @@ def box_coder(all_anchors, bbox_deltas, variances, pixel_offset=True): ...@@ -48,7 +49,7 @@ def box_coder(all_anchors, bbox_deltas, variances, pixel_offset=True):
anchor_loc[:, 2] = all_anchors[:, 0] + 0.5 * anchor_loc[:, 0] anchor_loc[:, 2] = all_anchors[:, 0] + 0.5 * anchor_loc[:, 0]
anchor_loc[:, 3] = all_anchors[:, 1] + 0.5 * anchor_loc[:, 1] anchor_loc[:, 3] = all_anchors[:, 1] + 0.5 * anchor_loc[:, 1]
# predicted bbox: bbox_center_x, bbox_center_y, bbox_width, bbox_height # predicted bbox: bbox_center_x, bbox_center_y, bbox_width, bbox_height
pred_bbox = np.zeros_like(bbox_deltas, dtype=np.float32) pred_bbox = np.zeros_like(bbox_deltas, dtype=np.float32)
if variances is not None: if variances is not None:
for i in range(bbox_deltas.shape[0]): for i in range(bbox_deltas.shape[0]):
...@@ -64,10 +65,12 @@ def box_coder(all_anchors, bbox_deltas, variances, pixel_offset=True): ...@@ -64,10 +65,12 @@ def box_coder(all_anchors, bbox_deltas, variances, pixel_offset=True):
1000 / 16.0))) * anchor_loc[i, 1] 1000 / 16.0))) * anchor_loc[i, 1]
else: else:
for i in range(bbox_deltas.shape[0]): for i in range(bbox_deltas.shape[0]):
pred_bbox[i, 0] = bbox_deltas[i, 0] * anchor_loc[i, 0] + anchor_loc[ pred_bbox[i,
i, 2] 0] = bbox_deltas[i, 0] * anchor_loc[i, 0] + anchor_loc[i,
pred_bbox[i, 1] = bbox_deltas[i, 1] * anchor_loc[i, 1] + anchor_loc[ 2]
i, 3] pred_bbox[i,
1] = bbox_deltas[i, 1] * anchor_loc[i, 1] + anchor_loc[i,
3]
pred_bbox[i, 2] = math.exp( pred_bbox[i, 2] = math.exp(
min(bbox_deltas[i, 2], math.log(1000 / 16.0))) * anchor_loc[i, min(bbox_deltas[i, 2], math.log(1000 / 16.0))) * anchor_loc[i,
0] 0]
...@@ -91,17 +94,21 @@ def clip_tiled_boxes(boxes, im_shape, pixel_offset=True): ...@@ -91,17 +94,21 @@ def clip_tiled_boxes(boxes, im_shape, pixel_offset=True):
) )
offset = 1 if pixel_offset else 0 offset = 1 if pixel_offset else 0
# x1 >= 0 # x1 >= 0
boxes[:, 0::4] = np.maximum( boxes[:,
np.minimum(boxes[:, 0::4], im_shape[1] - offset), 0) 0::4] = np.maximum(np.minimum(boxes[:, 0::4], im_shape[1] - offset),
0)
# y1 >= 0 # y1 >= 0
boxes[:, 1::4] = np.maximum( boxes[:,
np.minimum(boxes[:, 1::4], im_shape[0] - offset), 0) 1::4] = np.maximum(np.minimum(boxes[:, 1::4], im_shape[0] - offset),
0)
# x2 < im_shape[1] # x2 < im_shape[1]
boxes[:, 2::4] = np.maximum( boxes[:,
np.minimum(boxes[:, 2::4], im_shape[1] - offset), 0) 2::4] = np.maximum(np.minimum(boxes[:, 2::4], im_shape[1] - offset),
0)
# y2 < im_shape[0] # y2 < im_shape[0]
boxes[:, 3::4] = np.maximum( boxes[:,
np.minimum(boxes[:, 3::4], im_shape[0] - offset), 0) 3::4] = np.maximum(np.minimum(boxes[:, 3::4], im_shape[0] - offset),
0)
return boxes return boxes
...@@ -116,8 +123,8 @@ def filter_boxes(boxes, min_size, im_shape, pixel_offset=True): ...@@ -116,8 +123,8 @@ def filter_boxes(boxes, min_size, im_shape, pixel_offset=True):
if pixel_offset: if pixel_offset:
x_ctr = boxes[:, 0] + ws / 2. x_ctr = boxes[:, 0] + ws / 2.
y_ctr = boxes[:, 1] + hs / 2. y_ctr = boxes[:, 1] + hs / 2.
keep = np.where((ws >= min_size) & (hs >= min_size) & (x_ctr < im_shape[ keep = np.where((ws >= min_size) & (hs >= min_size)
1]) & (y_ctr < im_shape[0]))[0] & (x_ctr < im_shape[1]) & (y_ctr < im_shape[0]))[0]
else: else:
keep = np.where((ws >= min_size) & (hs >= min_size))[0] keep = np.where((ws >= min_size) & (hs >= min_size))[0]
return keep return keep
...@@ -309,10 +316,11 @@ def anchor_generator_in_python(input_feat, anchor_sizes, aspect_ratios, ...@@ -309,10 +316,11 @@ def anchor_generator_in_python(input_feat, anchor_sizes, aspect_ratios,
scale_h = anchor_size / stride[1] scale_h = anchor_size / stride[1]
w = scale_w * base_w w = scale_w * base_w
h = scale_h * base_h h = scale_h * base_h
out_anchors[h_idx, w_idx, idx, :] = [ out_anchors[h_idx, w_idx,
(x_ctr - 0.5 * (w - 1)), (y_ctr - 0.5 * (h - 1)), idx, :] = [(x_ctr - 0.5 * (w - 1)),
(x_ctr + 0.5 * (w - 1)), (y_ctr + 0.5 * (h - 1)) (y_ctr - 0.5 * (h - 1)),
] (x_ctr + 0.5 * (w - 1)),
(y_ctr + 0.5 * (h - 1))]
idx += 1 idx += 1
# set the variance. # set the variance.
...@@ -323,11 +331,13 @@ def anchor_generator_in_python(input_feat, anchor_sizes, aspect_ratios, ...@@ -323,11 +331,13 @@ def anchor_generator_in_python(input_feat, anchor_sizes, aspect_ratios,
class XPUGenerateProposalsV2Op(XPUOpTestWrapper): class XPUGenerateProposalsV2Op(XPUOpTestWrapper):
def __init__(self): def __init__(self):
self.op_name = 'generate_proposals_v2' self.op_name = 'generate_proposals_v2'
self.use_dynamic_create_class = False self.use_dynamic_create_class = False
class TestGenerateProposalsV2Op(XPUOpTest): class TestGenerateProposalsV2Op(XPUOpTest):
def set_data(self): def set_data(self):
self.init_input_shape() self.init_input_shape()
self.init_test_params() self.init_test_params()
...@@ -413,6 +423,7 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper): ...@@ -413,6 +423,7 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper):
self.nms_thresh, self.min_size, self.eta, self.pixel_offset) self.nms_thresh, self.min_size, self.eta, self.pixel_offset)
class TestGenerateProposalsV2OutLodOp(TestGenerateProposalsV2Op): class TestGenerateProposalsV2OutLodOp(TestGenerateProposalsV2Op):
def set_data(self): def set_data(self):
self.init_input_shape() self.init_input_shape()
self.init_test_params() self.init_test_params()
...@@ -439,11 +450,11 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper): ...@@ -439,11 +450,11 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper):
self.outputs = { self.outputs = {
'RpnRois': (self.rpn_rois[0], [self.rois_num]), 'RpnRois': (self.rpn_rois[0], [self.rois_num]),
'RpnRoiProbs': (self.rpn_roi_probs[0], [self.rois_num]), 'RpnRoiProbs': (self.rpn_roi_probs[0], [self.rois_num]),
'RpnRoisNum': (np.asarray( 'RpnRoisNum': (np.asarray(self.rois_num, dtype=np.int32))
self.rois_num, dtype=np.int32))
} }
class TestGenerateProposalsV2OpNoBoxLeft(TestGenerateProposalsV2Op): class TestGenerateProposalsV2OpNoBoxLeft(TestGenerateProposalsV2Op):
def init_test_params(self): def init_test_params(self):
self.pre_nms_topN = 12000 # train 12000, test 2000 self.pre_nms_topN = 12000 # train 12000, test 2000
self.post_nms_topN = 5000 # train 6000, test 1000 self.post_nms_topN = 5000 # train 6000, test 1000
...@@ -453,6 +464,7 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper): ...@@ -453,6 +464,7 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper):
self.pixel_offset = True self.pixel_offset = True
class TestGenerateProposalsV2OpNoOffset(TestGenerateProposalsV2Op): class TestGenerateProposalsV2OpNoOffset(TestGenerateProposalsV2Op):
def init_test_params(self): def init_test_params(self):
self.pre_nms_topN = 12000 # train 12000, test 2000 self.pre_nms_topN = 12000 # train 12000, test 2000
self.post_nms_topN = 5000 # train 6000, test 1000 self.post_nms_topN = 5000 # train 6000, test 1000
...@@ -461,11 +473,12 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper): ...@@ -461,11 +473,12 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper):
self.eta = 1. self.eta = 1.
self.pixel_offset = False self.pixel_offset = False
# """
class TestGenerateProposalsV2OpMaskRcnn1XPU(TestGenerateProposalsV2Op): class TestGenerateProposalsV2OpMaskRcnn1XPU(TestGenerateProposalsV2Op):
def init_input_shape(self): def init_input_shape(self):
self.input_feat_shape = (1, 20, 48, 64) self.input_feat_shape = (1, 20, 48, 64)
self.im_shape = np.array([[768, 1024]]).astype(self.dtype) # Another case is [768, 1024]
self.im_shape = np.array([[192, 256]]).astype(self.dtype)
def init_test_params(self): def init_test_params(self):
self.pre_nms_topN = 12000 # train 12000, test 2000 self.pre_nms_topN = 12000 # train 12000, test 2000
...@@ -526,19 +539,17 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper): ...@@ -526,19 +539,17 @@ class XPUGenerateProposalsV2Op(XPUOpTestWrapper):
self.outputs = { self.outputs = {
'RpnRois': (self.rpn_rois[0], [self.rois_num]), 'RpnRois': (self.rpn_rois[0], [self.rois_num]),
'RpnRoiProbs': (self.rpn_roi_probs[0], [self.rois_num]), 'RpnRoiProbs': (self.rpn_roi_probs[0], [self.rois_num]),
'RpnRoisNum': (np.asarray( 'RpnRoisNum': (np.asarray(self.rois_num, dtype=np.int32))
self.rois_num, dtype=np.int32))
} }
support_types = get_xpu_op_support_types('generate_proposals_v2') support_types = get_xpu_op_support_types('generate_proposals_v2')
for stype in support_types: for stype in support_types:
create_test_class( create_test_class(globals(),
globals(), XPUGenerateProposalsV2Op,
XPUGenerateProposalsV2Op, stype,
stype, test_grad=False,
test_grad=False, ignore_deivce_version=[core.XPUVersion.XPU1])
ignore_deivce_version=[core.XPUVersion.XPU1])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册