未验证 提交 1976cc4b 编写于 作者: Z zqw_1997 提交者: GitHub

[fluid remove]: remove paddle.fluid.layers.target_assign,...

[fluid remove]: remove paddle.fluid.layers.target_assign, paddle.fluid.layers.rpn_target_assign, paddle.fluid.layers.retinanet_target_assign and paddle.fluid.layers.ssd_loss (#48669)

* remove paddle.fluid.layers.nn.temporal_shift

* code check

* rm unittest

* remove ssd_loss, target_assigns

* remove target_assign, retinanet_target_assign, rpn_target_assign and ssd_loss
上级 4ab8a2ae
...@@ -163,74 +163,6 @@ class TestDetection(unittest.TestCase): ...@@ -163,74 +163,6 @@ class TestDetection(unittest.TestCase):
code_type='encode_center_size', code_type='encode_center_size',
) )
def test_detection_api(self):
program = Program()
with program_guard(program):
x = layers.data(name='x', shape=[4], dtype='float32')
y = layers.data(name='y', shape=[4], dtype='float32')
z = layers.data(name='z', shape=[4], dtype='float32', lod_level=1)
iou = layers.iou_similarity(x=x, y=y)
bcoder = layers.box_coder(
prior_box=x,
prior_box_var=y,
target_box=z,
code_type='encode_center_size',
)
self.assertIsNotNone(iou)
self.assertIsNotNone(bcoder)
matched_indices, matched_dist = layers.bipartite_match(iou)
self.assertIsNotNone(matched_indices)
self.assertIsNotNone(matched_dist)
gt = layers.data(
name='gt', shape=[1, 1], dtype='int32', lod_level=1
)
trg, trg_weight = layers.target_assign(
gt, matched_indices, mismatch_value=0
)
self.assertIsNotNone(trg)
self.assertIsNotNone(trg_weight)
gt2 = layers.data(
name='gt2', shape=[10, 4], dtype='float32', lod_level=1
)
trg, trg_weight = layers.target_assign(
gt2, matched_indices, mismatch_value=0
)
self.assertIsNotNone(trg)
self.assertIsNotNone(trg_weight)
print(str(program))
def test_ssd_loss(self):
program = Program()
with program_guard(program):
pb = layers.data(
name='prior_box',
shape=[10, 4],
append_batch_size=False,
dtype='float32',
)
pbv = layers.data(
name='prior_box_var',
shape=[10, 4],
append_batch_size=False,
dtype='float32',
)
loc = layers.data(name='target_box', shape=[10, 4], dtype='float32')
scores = layers.data(name='scores', shape=[10, 21], dtype='float32')
gt_box = layers.data(
name='gt_box', shape=[4], lod_level=1, dtype='float32'
)
gt_label = layers.data(
name='gt_label', shape=[1], lod_level=1, dtype='int32'
)
loss = layers.ssd_loss(loc, scores, gt_box, gt_label, pb, pbv)
self.assertIsNotNone(loss)
self.assertEqual(loss.shape[-1], 1)
print(str(program))
class TestPriorBox(unittest.TestCase): class TestPriorBox(unittest.TestCase):
def test_prior_box(self): def test_prior_box(self):
...@@ -521,87 +453,6 @@ class TestDetectionMAP(unittest.TestCase): ...@@ -521,87 +453,6 @@ class TestDetectionMAP(unittest.TestCase):
print(str(program)) print(str(program))
class TestRpnTargetAssign(unittest.TestCase):
def test_rpn_target_assign(self):
program = Program()
with program_guard(program):
bbox_pred_shape = [10, 50, 4]
cls_logits_shape = [10, 50, 2]
anchor_shape = [50, 4]
bbox_pred = layers.data(
name='bbox_pred',
shape=bbox_pred_shape,
append_batch_size=False,
dtype='float32',
)
cls_logits = layers.data(
name='cls_logits',
shape=cls_logits_shape,
append_batch_size=False,
dtype='float32',
)
anchor_box = layers.data(
name='anchor_box',
shape=anchor_shape,
append_batch_size=False,
dtype='float32',
)
anchor_var = layers.data(
name='anchor_var',
shape=anchor_shape,
append_batch_size=False,
dtype='float32',
)
gt_boxes = layers.data(
name='gt_boxes', shape=[4], lod_level=1, dtype='float32'
)
is_crowd = layers.data(
name='is_crowd',
shape=[1, 10],
dtype='int32',
lod_level=1,
append_batch_size=False,
)
im_info = layers.data(
name='im_info',
shape=[1, 3],
dtype='float32',
lod_level=1,
append_batch_size=False,
)
outs = layers.rpn_target_assign(
bbox_pred=bbox_pred,
cls_logits=cls_logits,
anchor_box=anchor_box,
anchor_var=anchor_var,
gt_boxes=gt_boxes,
is_crowd=is_crowd,
im_info=im_info,
rpn_batch_size_per_im=256,
rpn_straddle_thresh=0.0,
rpn_fg_fraction=0.5,
rpn_positive_overlap=0.7,
rpn_negative_overlap=0.3,
use_random=False,
)
pred_scores = outs[0]
pred_loc = outs[1]
tgt_lbl = outs[2]
tgt_bbox = outs[3]
bbox_inside_weight = outs[4]
self.assertIsNotNone(pred_scores)
self.assertIsNotNone(pred_loc)
self.assertIsNotNone(tgt_lbl)
self.assertIsNotNone(tgt_bbox)
self.assertIsNotNone(bbox_inside_weight)
assert pred_scores.shape[1] == 1
assert pred_loc.shape[1] == 4
assert pred_loc.shape[1] == tgt_bbox.shape[1]
print(str(program))
class TestGenerateProposals(LayerTest): class TestGenerateProposals(LayerTest):
def test_generate_proposals(self): def test_generate_proposals(self):
scores_np = np.random.rand(2, 3, 4, 4).astype('float32') scores_np = np.random.rand(2, 3, 4, 4).astype('float32')
......
...@@ -3288,70 +3288,6 @@ class TestBook(LayerTest): ...@@ -3288,70 +3288,6 @@ class TestBook(LayerTest):
) )
return out return out
def test_retinanet_target_assign(self):
with program_guard(
fluid.default_main_program(), fluid.default_startup_program()
):
bbox_pred = layers.data(
name='bbox_pred',
shape=[1, 100, 4],
append_batch_size=False,
dtype='float32',
)
cls_logits = layers.data(
name='cls_logits',
shape=[1, 100, 10],
append_batch_size=False,
dtype='float32',
)
anchor_box = layers.data(
name='anchor_box',
shape=[100, 4],
append_batch_size=False,
dtype='float32',
)
anchor_var = layers.data(
name='anchor_var',
shape=[100, 4],
append_batch_size=False,
dtype='float32',
)
gt_boxes = layers.data(
name='gt_boxes',
shape=[10, 4],
append_batch_size=False,
dtype='float32',
)
gt_labels = layers.data(
name='gt_labels',
shape=[10, 1],
append_batch_size=False,
dtype='int32',
)
is_crowd = layers.data(
name='is_crowd',
shape=[1],
append_batch_size=False,
dtype='int32',
)
im_info = layers.data(
name='im_info',
shape=[1, 3],
append_batch_size=False,
dtype='float32',
)
return layers.retinanet_target_assign(
bbox_pred,
cls_logits,
anchor_box,
anchor_var,
gt_boxes,
gt_labels,
is_crowd,
im_info,
10,
)
def test_addmm(self): def test_addmm(self):
with program_guard( with program_guard(
fluid.default_main_program(), fluid.default_startup_program() fluid.default_main_program(), fluid.default_startup_program()
......
...@@ -23,9 +23,6 @@ from test_generate_proposal_labels_op import ( ...@@ -23,9 +23,6 @@ from test_generate_proposal_labels_op import (
_generate_groundtruth, _generate_groundtruth,
) )
import paddle.fluid as fluid
from paddle.fluid import Program, program_guard
def rpn_target_assign( def rpn_target_assign(
anchor_by_gt_overlap, anchor_by_gt_overlap,
...@@ -485,424 +482,5 @@ class TestRetinanetTargetAssignOp(OpTest): ...@@ -485,424 +482,5 @@ class TestRetinanetTargetAssignOp(OpTest):
self.check_output() self.check_output()
class TestRetinanetTargetAssignOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
bbox_pred1 = fluid.data(
name='bbox_pred1', shape=[1, 100, 4], dtype='float32'
)
cls_logits1 = fluid.data(
name='cls_logits1', shape=[1, 100, 10], dtype='float32'
)
anchor_box1 = fluid.data(
name='anchor_box1', shape=[100, 4], dtype='float32'
)
anchor_var1 = fluid.data(
name='anchor_var1', shape=[100, 4], dtype='float32'
)
gt_boxes1 = fluid.data(
name='gt_boxes1', shape=[10, 4], dtype='float32'
)
gt_labels1 = fluid.data(
name='gt_labels1', shape=[10, 1], dtype='int32'
)
is_crowd1 = fluid.data(name='is_crowd1', shape=[1], dtype='float32')
im_info1 = fluid.data(
name='im_info1', shape=[1, 3], dtype='float32'
)
# The `bbox_pred` must be Variable and the data type of `bbox_pred` Tensor
# one of float32 and float64.
def test_bbox_pred_type():
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
[1],
cls_logits1,
anchor_box1,
anchor_var1,
gt_boxes1,
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_bbox_pred_type)
def test_bbox_pred_tensor_dtype():
bbox_pred2 = fluid.data(
name='bbox_pred2', shape=[1, 100, 4], dtype='intt32'
)
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred2,
cls_logits1,
anchor_box1,
anchor_var1,
gt_boxes1,
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_bbox_pred_tensor_dtype)
# The `cls_logits` must be Variable and the data type of `cls_logits` Tensor
# one of float32 and float64.
def test_cls_logits_type():
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
2,
anchor_box1,
anchor_var1,
gt_boxes1,
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_cls_logits_type)
def test_cls_logits_tensor_dtype():
cls_logits2 = fluid.data(
name='cls_logits2', shape=[1, 100, 10], dtype='int32'
)
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits2,
anchor_box1,
anchor_var1,
gt_boxes1,
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_cls_logits_tensor_dtype)
# The `anchor_box` must be Variable and the data type of `anchor_box` Tensor
# one of float32 and float64.
def test_anchor_box_type():
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
[5],
anchor_var1,
gt_boxes1,
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_anchor_box_type)
def test_anchor_box_tensor_dtype():
anchor_box2 = fluid.data(
name='anchor_box2', shape=[100, 4], dtype='int32'
)
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box2,
anchor_var1,
gt_boxes1,
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_anchor_box_tensor_dtype)
# The `anchor_var` must be Variable and the data type of `anchor_var` Tensor
# one of float32 and float64.
def test_anchor_var_type():
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
5,
gt_boxes1,
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_anchor_var_type)
def test_anchor_var_tensor_dtype():
anchor_var2 = fluid.data(
name='anchor_var2', shape=[100, 4], dtype='int32'
)
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
anchor_var2,
gt_boxes1,
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_anchor_var_tensor_dtype)
# The `gt_boxes` must be Variable and the data type of `gt_boxes` Tensor
# one of float32 and float64.
def test_gt_boxes_type():
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
anchor_var1,
[4],
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_gt_boxes_type)
def test_gt_boxes_tensor_dtype():
gt_boxes2 = fluid.data(
name='gt_boxes2', shape=[10, 4], dtype='int32'
)
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
anchor_var1,
gt_boxes2,
gt_labels1,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_gt_boxes_tensor_dtype)
# The `gt_label` must be Variable and the data type of `gt_label` Tensor
# int32.
def test_gt_label_type():
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
anchor_var1,
gt_boxes1,
9,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_gt_label_type)
def test_gt_label_tensor_dtype():
gt_labels2 = fluid.data(
name='label2', shape=[10, 1], dtype='float32'
)
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
anchor_var1,
gt_boxes1,
gt_labels2,
is_crowd1,
im_info1,
10,
)
self.assertRaises(TypeError, test_gt_label_tensor_dtype)
# The `is_crowd` must be Variable and the data type of `is_crowd` Tensor
# int32.
def test_is_crowd_type():
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
anchor_var1,
gt_boxes1,
gt_labels1,
[10],
im_info1,
10,
)
self.assertRaises(TypeError, test_is_crowd_type)
def test_is_crowd_tensor_dtype():
is_crowd2 = fluid.data(
name='is_crowd2', shape=[10, 1], dtype='float32'
)
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
anchor_var1,
gt_boxes1,
gt_labels1,
is_crowd2,
im_info1,
10,
)
self.assertRaises(TypeError, test_is_crowd_tensor_dtype)
# The `im_info` must be Variable and the data type of `im_info` Tensor
# must be one of float32 and float64.
def test_im_info_type():
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
anchor_var1,
gt_boxes1,
gt_labels1,
is_crowd1,
1,
10,
)
self.assertRaises(TypeError, test_im_info_type)
def test_im_info_tensor_dtype():
im_info2 = fluid.data(
name='im_info2', shape=[1, 3], dtype='int32'
)
(
score_pred,
loc_pred,
score_target,
loc_target,
bbox_inside_weight,
fg_num,
) = fluid.layers.retinanet_target_assign(
bbox_pred1,
cls_logits1,
anchor_box1,
anchor_var1,
gt_boxes1,
gt_labels1,
is_crowd1,
im_info2,
10,
)
self.assertRaises(TypeError, test_im_info_tensor_dtype)
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.
先完成此消息的编辑!
想要评论请 注册