Ejemplo n.º 1
0
 def test_ioa(self):
     ioa21 = np_box_mask_list_ops.ioa(self.box_mask_list1,
                                      self.box_mask_list2)
     expected_ioa21 = np.array(
         [[1.0, 0.0, 8.0 / 25.0], [0.0, 9.0 / 15.0, 7.0 / 25.0]],
         dtype=np.float32)
     self.assertAllClose(ioa21, expected_ioa21)
Ejemplo n.º 2
0
    def _get_overlaps_and_scores_mask_mode(self, detected_boxes,
                                           detected_scores, detected_masks,
                                           groundtruth_boxes,
                                           groundtruth_masks,
                                           groundtruth_is_group_of_list):
        """Computes overlaps and scores between detected and groudntruth masks.

    Args:
      detected_boxes: A numpy array of shape [N, 4] representing detected box
        coordinates
      detected_scores: A 1-d numpy array of length N representing classification
        score
      detected_masks: A uint8 numpy array of shape [N, height, width]. If not
        None, the scores will be computed based on masks.
      groundtruth_boxes: A numpy array of shape [M, 4] representing ground truth
        box coordinates
      groundtruth_masks: A uint8 numpy array of shape [M, height, width].
      groundtruth_is_group_of_list: A boolean numpy array of length M denoting
        whether a ground truth box has group-of tag. If a groundtruth box is
        group-of box, every detection matching this box is ignored.

    Returns:
      iou: A float numpy array of size [num_detected_boxes, num_gt_boxes]. If
          gt_non_group_of_boxlist.num_boxes() == 0 it will be None.
      ioa: A float numpy array of size [num_detected_boxes, num_gt_boxes]. If
          gt_group_of_boxlist.num_boxes() == 0 it will be None.
      scores: The score of the detected boxlist.
      num_boxes: Number of non-maximum suppressed detected boxes.
    """

        #print('len(detected_boxes)',len(detected_boxes))
        detected_boxlist = np_box_mask_list.BoxMaskList(
            box_data=detected_boxes, mask_data=detected_masks)
        detected_boxlist.add_field('scores', detected_scores)
        #print('detected_boxlist.num_boxes()',detected_boxlist.num_boxes())
        detected_boxlist = np_box_mask_list_ops.non_max_suppression(
            detected_boxlist, self.nms_max_output_boxes,
            self.nms_iou_threshold)
        #print('sfter nms',detected_boxlist.num_boxes())
        gt_non_group_of_boxlist = np_box_mask_list.BoxMaskList(
            box_data=groundtruth_boxes[~groundtruth_is_group_of_list],
            mask_data=groundtruth_masks[~groundtruth_is_group_of_list])
        gt_group_of_boxlist = np_box_mask_list.BoxMaskList(
            box_data=groundtruth_boxes[groundtruth_is_group_of_list],
            mask_data=groundtruth_masks[groundtruth_is_group_of_list])
        iou = np_box_mask_list_ops.iou(detected_boxlist,
                                       gt_non_group_of_boxlist)
        ioa = np.transpose(
            np_box_mask_list_ops.ioa(gt_group_of_boxlist, detected_boxlist))
        scores = detected_boxlist.get_field('scores')
        num_boxes = detected_boxlist.num_boxes()
        return iou, ioa, scores, num_boxes
Ejemplo n.º 3
0
  def _get_overlaps_and_scores_mask_mode(
      self, detected_boxes, detected_scores, detected_masks, groundtruth_boxes,
      groundtruth_masks, groundtruth_is_group_of_list):
    """Computes overlaps and scores between detected and groudntruth masks.

    Args:
      detected_boxes: A numpy array of shape [N, 4] representing detected box
          coordinates
      detected_scores: A 1-d numpy array of length N representing classification
          score
      detected_masks: A uint8 numpy array of shape [N, height, width]. If not
          None, the scores will be computed based on masks.
      groundtruth_boxes: A numpy array of shape [M, 4] representing ground truth
          box coordinates
      groundtruth_masks: A uint8 numpy array of shape [M, height, width].
      groundtruth_is_group_of_list: A boolean numpy array of length M denoting
          whether a ground truth box has group-of tag. If a groundtruth box
          is group-of box, every detection matching this box is ignored.

    Returns:
      iou: A float numpy array of size [num_detected_boxes, num_gt_boxes]. If
          gt_non_group_of_boxlist.num_boxes() == 0 it will be None.
      ioa: A float numpy array of size [num_detected_boxes, num_gt_boxes]. If
          gt_group_of_boxlist.num_boxes() == 0 it will be None.
      scores: The score of the detected boxlist.
      num_boxes: Number of non-maximum suppressed detected boxes.
    """
    detected_boxlist = np_box_mask_list.BoxMaskList(
        box_data=detected_boxes, mask_data=detected_masks)
    detected_boxlist.add_field('scores', detected_scores)
    detected_boxlist = np_box_mask_list_ops.non_max_suppression(
        detected_boxlist, self.nms_max_output_boxes, self.nms_iou_threshold)
    gt_non_group_of_boxlist = np_box_mask_list.BoxMaskList(
        box_data=groundtruth_boxes[~groundtruth_is_group_of_list],
        mask_data=groundtruth_masks[~groundtruth_is_group_of_list])
    gt_group_of_boxlist = np_box_mask_list.BoxMaskList(
        box_data=groundtruth_boxes[groundtruth_is_group_of_list],
        mask_data=groundtruth_masks[groundtruth_is_group_of_list])
    iou = np_box_mask_list_ops.iou(detected_boxlist, gt_non_group_of_boxlist)
    ioa = np.transpose(
        np_box_mask_list_ops.ioa(gt_group_of_boxlist, detected_boxlist))
    scores = detected_boxlist.get_field('scores')
    num_boxes = detected_boxlist.num_boxes()
    return iou, ioa, scores, num_boxes
Ejemplo n.º 4
0
 def test_ioa(self):
   ioa21 = np_box_mask_list_ops.ioa(self.box_mask_list1, self.box_mask_list2)
   expected_ioa21 = np.array([[1.0, 0.0, 8.0/25.0],
                              [0.0, 9.0/15.0, 7.0/25.0]],
                             dtype=np.float32)
   self.assertAllClose(ioa21, expected_ioa21)