Пример #1
0
    def _assign_targets(self,
                        groundtruth_boxes_list,
                        groundtruth_classes_list,
                        groundtruth_keypoints_list=None,
                        groundtruth_weights_list=None):
        """Assign groundtruth targets.

    Adds a background class to each one-hot encoding of groundtruth classes
    and uses target assigner to obtain regression and classification targets.

    Args:
      groundtruth_boxes_list: a list of 2-D tensors of shape [num_boxes, 4]
        containing coordinates of the groundtruth boxes.
          Groundtruth boxes are provided in [y_min, x_min, y_max, x_max]
          format and assumed to be normalized and clipped
          relative to the image window with y_min <= y_max and x_min <= x_max.
      groundtruth_classes_list: a list of 2-D one-hot (or k-hot) tensors of
        shape [num_boxes, num_classes] containing the class targets with the 0th
        index assumed to map to the first non-background class.
      groundtruth_keypoints_list: (optional) a list of 3-D tensors of shape
        [num_boxes, num_keypoints, 2]
      groundtruth_weights_list: A list of 1-D tf.float32 tensors of shape
        [num_boxes] containing weights for groundtruth boxes.

    Returns:
      batch_cls_targets: a tensor with shape [batch_size, num_anchors,
        num_classes],
      batch_cls_weights: a tensor with shape [batch_size, num_anchors],
      batch_reg_targets: a tensor with shape [batch_size, num_anchors,
        box_code_dimension]
      batch_reg_weights: a tensor with shape [batch_size, num_anchors],
      match_list: a list of matcher.Match objects encoding the match between
        anchors and groundtruth boxes for each image of the batch,
        with rows of the Match objects corresponding to groundtruth boxes
        and columns corresponding to anchors.
    """
        groundtruth_boxlists = [
            box_list.BoxList(boxes) for boxes in groundtruth_boxes_list
        ]
        if self._add_background_class:
            groundtruth_classes_with_background_list = [
                tf.pad(one_hot_encoding, [[0, 0], [1, 0]], mode='CONSTANT')
                for one_hot_encoding in groundtruth_classes_list
            ]
        else:
            groundtruth_classes_with_background_list = groundtruth_classes_list

        if groundtruth_keypoints_list is not None:
            for boxlist, keypoints in zip(groundtruth_boxlists,
                                          groundtruth_keypoints_list):
                boxlist.add_field(fields.BoxListFields.keypoints, keypoints)
        return target_assigner.batch_assign_targets(
            self._target_assigner, self.anchors, groundtruth_boxlists,
            groundtruth_classes_with_background_list,
            self._unmatched_class_label, groundtruth_weights_list)
Пример #2
0
 def graph_fn(anchor_means, groundtruth_boxlist1, groundtruth_boxlist2):
     box_list1 = box_list.BoxList(groundtruth_boxlist1)
     box_list2 = box_list.BoxList(groundtruth_boxlist2)
     gt_box_batch = [box_list1, box_list2]
     gt_class_targets = [None, None]
     anchors_boxlist = box_list.BoxList(anchor_means)
     agnostic_target_assigner = self._get_target_assigner()
     (cls_targets, cls_weights, reg_targets, reg_weights,
      _) = targetassigner.batch_assign_targets(agnostic_target_assigner,
                                               anchors_boxlist,
                                               gt_box_batch,
                                               gt_class_targets)
     return (cls_targets, cls_weights, reg_targets, reg_weights)
Пример #3
0
        def graph_fn(anchor_means, groundtruth_box_corners, gt_class_targets):
            groundtruth_boxlist = box_list.BoxList(groundtruth_box_corners)
            gt_box_batch = [groundtruth_boxlist]
            gt_class_targets_batch = [gt_class_targets]
            anchors_boxlist = box_list.BoxList(anchor_means)

            multiclass_target_assigner = self._get_target_assigner()
            num_classes = 3
            unmatched_class_label = tf.constant([1] + num_classes * [0],
                                                tf.float32)
            (cls_targets, cls_weights, reg_targets, reg_weights,
             _) = targetassigner.batch_assign_targets(
                 multiclass_target_assigner, anchors_boxlist, gt_box_batch,
                 gt_class_targets_batch, unmatched_class_label)
            return (cls_targets, cls_weights, reg_targets, reg_weights)
Пример #4
0
 def graph_fn(anchor_means, groundtruth_boxlist1, groundtruth_boxlist2,
              class_targets1, class_targets2):
     box_list1 = box_list.BoxList(groundtruth_boxlist1)
     box_list2 = box_list.BoxList(groundtruth_boxlist2)
     gt_box_batch = [box_list1, box_list2]
     gt_class_targets = [class_targets1, class_targets2]
     anchors_boxlist = box_list.BoxList(anchor_means)
     multiclass_target_assigner = self._get_target_assigner()
     target_dimensions = (2, 3)
     unmatched_class_label = tf.constant(np.zeros(target_dimensions),
                                         tf.float32)
     (cls_targets, cls_weights, reg_targets, reg_weights,
      _) = targetassigner.batch_assign_targets(
          multiclass_target_assigner, anchors_boxlist, gt_box_batch,
          gt_class_targets, unmatched_class_label)
     return (cls_targets, cls_weights, reg_targets, reg_weights)
Пример #5
0
 def graph_fn(anchor_means, groundtruth_boxlist1, groundtruth_boxlist2,
              class_targets1, class_targets2, groundtruth_weights1,
              groundtruth_weights2):
     box_list1 = box_list.BoxList(groundtruth_boxlist1)
     box_list2 = box_list.BoxList(groundtruth_boxlist2)
     gt_box_batch = [box_list1, box_list2]
     gt_class_targets = [class_targets1, class_targets2]
     gt_weights = [groundtruth_weights1, groundtruth_weights2]
     anchors_boxlist = box_list.BoxList(anchor_means)
     multiclass_target_assigner = self._get_target_assigner()
     num_classes = 3
     unmatched_class_label = tf.constant([1] + num_classes * [0],
                                         tf.float32)
     (cls_targets, cls_weights, reg_targets, reg_weights,
      _) = targetassigner.batch_assign_targets(
          multiclass_target_assigner, anchors_boxlist, gt_box_batch,
          gt_class_targets, unmatched_class_label, gt_weights)
     return (cls_targets, cls_weights, reg_targets, reg_weights)