|
|
|
@ -16,7 +16,9 @@ from __future__ import print_function
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
import numpy as np
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
|
import paddle.fluid.core as core
|
|
|
|
|
from paddle.fluid import Program, program_guard
|
|
|
|
|
from op_test import OpTest
|
|
|
|
|
from test_anchor_generator_op import anchor_generator_in_python
|
|
|
|
|
from test_generate_proposal_labels_op import _generate_groundtruth
|
|
|
|
@ -393,5 +395,169 @@ class TestRetinanetTargetAssignOp(OpTest):
|
|
|
|
|
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__':
|
|
|
|
|
unittest.main()
|
|
|
|
|