Beispiel #1
0
    def test_different_iou_threshold(self):
        boxes = np.array([[0, 0, 20, 100], [0, 0, 20, 80],
                          [200, 200, 210, 300], [200, 200, 210, 250]],
                         dtype=float)
        boxlist = np_box_list.BoxList(boxes)
        boxlist.add_field('scores', np.array([0.9, 0.8, 0.7, 0.6]))
        max_output_size = 4

        iou_threshold = .4
        expected_boxes = np.array([
            [0, 0, 20, 100],
            [200, 200, 210, 300],
        ],
                                  dtype=float)
        nms_boxlist = np_box_list_ops.non_max_suppression(
            boxlist, max_output_size, iou_threshold)
        self.assertAllClose(nms_boxlist.get(), expected_boxes)

        iou_threshold = .5
        expected_boxes = np.array(
            [[0, 0, 20, 100], [200, 200, 210, 300], [200, 200, 210, 250]],
            dtype=float)
        nms_boxlist = np_box_list_ops.non_max_suppression(
            boxlist, max_output_size, iou_threshold)
        self.assertAllClose(nms_boxlist.get(), expected_boxes)

        iou_threshold = .8
        expected_boxes = np.array([[0, 0, 20, 100], [0, 0, 20, 80],
                                   [200, 200, 210, 300], [200, 200, 210, 250]],
                                  dtype=float)
        nms_boxlist = np_box_list_ops.non_max_suppression(
            boxlist, max_output_size, iou_threshold)
        self.assertAllClose(nms_boxlist.get(), expected_boxes)
Beispiel #2
0
    def test_with_no_scores_field(self):
        boxlist = np_box_list.BoxList(self._boxes)
        max_output_size = 3
        iou_threshold = 0.5

        with self.assertRaises(ValueError):
            np_box_list_ops.non_max_suppression(boxlist, max_output_size,
                                                iou_threshold)
Beispiel #3
0
 def test_select_from_ten_indentical_boxes(self):
     boxes = np.array(10 * [[0, 0, 1, 1]], dtype=float)
     boxlist = np_box_list.BoxList(boxes)
     boxlist.add_field('scores', np.array(10 * [0.8]))
     iou_threshold = .5
     max_output_size = 3
     expected_boxes = np.array([[0, 0, 1, 1]], dtype=float)
     nms_boxlist = np_box_list_ops.non_max_suppression(
         boxlist, max_output_size, iou_threshold)
     self.assertAllClose(nms_boxlist.get(), expected_boxes)
Beispiel #4
0
    def test_select_at_most_two_from_three_clusters(self):
        boxlist = np_box_list.BoxList(self._boxes)
        boxlist.add_field('scores',
                          np.array([.9, .75, .6, .95, .5, .3], dtype=float))
        max_output_size = 2
        iou_threshold = 0.5

        expected_boxes = np.array([[0, 10, 1, 11], [0, 0, 1, 1]], dtype=float)
        nms_boxlist = np_box_list_ops.non_max_suppression(
            boxlist, max_output_size, iou_threshold)
        self.assertAllClose(nms_boxlist.get(), expected_boxes)
Beispiel #5
0
    def test_nms_disabled_max_output_size_equals_three(self):
        boxlist = np_box_list.BoxList(self._boxes)
        boxlist.add_field('scores',
                          np.array([.9, .75, .6, .95, .2, .3], dtype=float))
        max_output_size = 3
        iou_threshold = 1.  # No NMS

        expected_boxes = np.array(
            [[0, 10, 1, 11], [0, 0, 1, 1], [0, 0.1, 1, 1.1]], dtype=float)
        nms_boxlist = np_box_list_ops.non_max_suppression(
            boxlist, max_output_size, iou_threshold)
        self.assertAllClose(nms_boxlist.get(), expected_boxes)