Ejemplo n.º 1
0
    def sample_mini_batch(self, anchor_box_list_gt, anchor_box_list,
                          class_labels):

        with tf.variable_scope('avod_create_mb_mask'):
            # Get IoU for every anchor
            all_ious = box_list_ops.iou(anchor_box_list_gt, anchor_box_list)
            max_ious = tf.reduce_max(all_ious, axis=0)
            max_iou_indices = tf.argmax(all_ious, axis=0)

            # Sample a pos/neg mini-batch from anchors with highest IoU match
            mini_batch_panoptic_utils = self.dataset.panoptic_utils.mini_batch_panoptic_utils
            mb_mask, mb_pos_mask = mini_batch_panoptic_utils.sample_avod_mini_batch(
                max_ious)
            # mb_pos_mask = tf.Print(mb_pos_mask, ['line 683(avod) : tf.shape(mb_pos_mask) =', tf.shape(mb_pos_mask)], summarize=100)
            # mb_pos_mask = tf.Print(mb_pos_mask, ['line 684(avod) : mb_pos_mask =', mb_pos_mask], summarize=100)
            # mb_mask = tf.Print(mb_mask, ['line 685(avod) : tf.shape(mb_mask) =', tf.shape(mb_mask)], summarize=100)
            # mb_mask = tf.Print(mb_mask, ['line 686(avod) : mb_mask =', mb_mask], summarize=100)
            # max_iou_indices = tf.Print(max_iou_indices, ['line 687(avod) : max_iou_indices =', max_iou_indices], summarize=100)

            # class_labels: a tensor of shape [num_of_classes] indicating the
            #     class labels as indices. For instance indices=[0, 1, 2, 3]
            #     indicating 'background, car, pedestrian, cyclist' etc.
            # For pedestrian training only, class_labels =[1]

            mb_class_label_indices = mini_batch_panoptic_utils.mask_class_label_indices(
                mb_pos_mask, mb_mask, max_iou_indices, class_labels)
            # mb_class_label_indices : a tensor of boolean mask for class label
            #     indices. This gives the indices for the positive classes and
            #     masks negatives or background classes by zero's.

            mb_gt_indices = tf.boolean_mask(max_iou_indices, mb_mask)

        return mb_mask, mb_class_label_indices, mb_gt_indices
Ejemplo n.º 2
0
 def test_iouworks_on_empty_inputs(self):
     corners1 = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]])
     corners2 = tf.constant([[3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0],
                             [0.0, 0.0, 20.0, 20.0]])
     boxes1 = box_list.BoxList(corners1)
     boxes2 = box_list.BoxList(corners2)
     boxes_empty = box_list.BoxList(tf.zeros((0, 4)))
     iou_empty_1 = box_list_ops.iou(boxes1, boxes_empty)
     iou_empty_2 = box_list_ops.iou(boxes_empty, boxes2)
     iou_empty_3 = box_list_ops.iou(boxes_empty, boxes_empty)
     with self.test_session() as sess:
         iou_output_1, iou_output_2, iou_output_3 = sess.run(
             [iou_empty_1, iou_empty_2, iou_empty_3])
         self.assertAllEqual(iou_output_1.shape, (2, 0))
         self.assertAllEqual(iou_output_2.shape, (0, 3))
         self.assertAllEqual(iou_output_3.shape, (0, 0))
Ejemplo n.º 3
0
 def test_iou(self):
     corners1 = tf.constant([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]])
     corners2 = tf.constant([[3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0],
                             [0.0, 0.0, 20.0, 20.0]])
     exp_output = [[2.0 / 16.0, 0, 6.0 / 400.0],
                   [1.0 / 16.0, 0.0, 5.0 / 400.0]]
     boxes1 = box_list.BoxList(corners1)
     boxes2 = box_list.BoxList(corners2)
     iou = box_list_ops.iou(boxes1, boxes2)
     with self.test_session() as sess:
         iou_output = sess.run(iou)
         self.assertAllClose(iou_output, exp_output)
Ejemplo n.º 4
0
    def sample_mini_batch(self, anchor_box_list_gt, anchor_box_list,
                          class_labels):

        with tf.variable_scope('pplp_create_mb_mask'):
            # Get IoU for every anchor
            all_ious = box_list_ops.iou(anchor_box_list_gt, anchor_box_list)
            # all_ious = tf.Print(all_ious, ['-=-=-=-=-=-=-line 753(pplp) : all_ious =', all_ious], summarize=100)
            # all_ious = tf.Print(all_ious, ['-=-=-=-=-=-=-line 754(pplp) : tf.shape(all_ious) =', tf.shape(all_ious)], summarize=100) #  tf.shape(all_ious) = [4 265]
            max_ious = tf.reduce_max(all_ious, axis=0)
            # max_ious = tf.Print(max_ious, ['-=-=-=-=-=-=-line 756(pplp) : max_ious =', max_ious], summarize=100)
            # max_ious =[0 0 0 0 0 0 0.225453332 0 0 0 0 0 0 0 0 0 0 0 0 0 0.417117327 0 0.404093683 0 0 0.00502740964 0 0.199674159 0 0.288573176 0 0 0.0159720983 0 0 0 0.169192255 0.00572701544 0 0 0 0 0 0 0.0461278595 0 0 0 0 0 0 0 0 0.128080159 0 0 0 0 0 0.615373969 0 0 0 0 0 0 0 0 0 0 0 0 0.309623659 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0571997948 0 0 0 0 0 0 0 0 0 0 0 0.106632032...]
            # max_ious = tf.Print(max_ious, ['-=-=-=-=-=-=-line 757(pplp) : tf.shape(max_ious) =', tf.shape(max_ious)], summarize=100) #  tf.shape(max_ious) = [265]
            max_iou_indices = tf.argmax(all_ious, axis=0)
            # max_iou_indices = tf.Print(max_iou_indices, ['-=-=-=-=-=-=-line 759(pplp) : max_iou_indices =', max_iou_indices], summarize=100)
            # max_iou_indices =[0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 2 0 0 2 0 3 0 0 0 0 2 0 0 0 2 2 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 3 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0...]
            # max_iou_indices = tf.Print(max_iou_indices, ['-=-=-=-=-=-=-line 760(pplp) : tf.shape(max_iou_indices) =', tf.shape(max_iou_indices)], summarize=100) #  tf.shape(max_iou_indices) = [265]

            # Sample a pos/neg mini-batch from anchors with highest IoU match
            mini_batch_panoptic_utils = self.dataset.panoptic_utils.mini_batch_panoptic_utils
            mb_mask, mb_pos_mask = mini_batch_panoptic_utils.sample_avod_mini_batch(
                max_ious)
            # mb_pos_mask = tf.Print(mb_pos_mask, ['-=-=-=-=-=-=-line 768(pplp) : tf.shape(mb_pos_mask) =', tf.shape(mb_pos_mask)], summarize=100)
            # mb_pos_mask = tf.Print(mb_pos_mask, ['-=-=-=-=-=-=-line 769(pplp) : mb_pos_mask =', mb_pos_mask], summarize=1000)
            # mb_mask = tf.Print(mb_mask, ['-=-=-=-=-=-=-line 770(pplp) : tf.shape(mb_mask) =', tf.shape(mb_mask)], summarize=100)
            # mb_mask = tf.Print(mb_mask, ['-=-=-=-=-=-=-line 771(pplp) : mb_mask =', mb_mask], summarize=1000)
            # max_iou_indices = tf.Print(max_iou_indices, ['line 687(pplp) : max_iou_indices =', max_iou_indices], summarize=100)

            # class_labels: a tensor of shape [num_of_classes] indicating the
            #     class labels as indices. For instance indices=[0, 1, 2, 3]
            #     indicating 'background, car, pedestrian, cyclist' etc.
            # For pedestrian training only, class_labels =[1]

            mb_class_label_indices = mini_batch_panoptic_utils.mask_class_label_indices(
                mb_pos_mask, mb_mask, max_iou_indices, class_labels)
            # mb_class_label_indices = tf.Print(mb_class_label_indices, ['-=-=-=-=-=-=-line 781(pplp) : tf.shape(mb_class_label_indices) =', tf.shape(mb_class_label_indices)], summarize=100) #  tf.shape(mb_gt_indices) = [265]
            # mb_class_label_indices = tf.Print(mb_class_label_indices, ['-=-=-=-=-=-=-line 782(pplp) : mb_class_label_indices =', mb_class_label_indices], summarize=1000) #  tf.shape(mb_gt_indices) = [265]
            # mb_class_label_indices : a tensor of boolean mask for class label
            #     indices. This gives the indices for the positive classes and
            #     masks negatives or background classes by zero's.

            mb_gt_indices = tf.boolean_mask(max_iou_indices, mb_mask)
            # mb_gt_indices = tf.Print(mb_gt_indices, ['-=-=-=-=-=-=-line 786(pplp) : tf.shape(mb_gt_indices) =', tf.shape(mb_gt_indices)], summarize=100) #  tf.shape(mb_gt_indices) = [265]
            # mb_gt_indices = tf.Print(mb_gt_indices, ['-=-=-=-=-=-=-line 787(pplp) : mb_gt_indices =', mb_gt_indices], summarize=1000) #  tf.shape(mb_gt_indices) = [265]

        return mb_mask, mb_class_label_indices, mb_gt_indices
Ejemplo n.º 5
0
    def sample_mini_batch(self, anchor_box_list_gt, anchor_box_list,
                          class_labels):

        with tf.variable_scope('avod_create_mb_mask'):
            # Get IoU for every anchor
            all_ious = box_list_ops.iou(anchor_box_list_gt, anchor_box_list)
            max_ious = tf.reduce_max(all_ious, axis=0)
            max_iou_indices = tf.argmax(all_ious, axis=0)

            # Sample a pos/neg mini-batch from anchors with highest IoU match
            mini_batch_utils = self.dataset.kitti_utils.mini_batch_utils
            mb_mask, mb_pos_mask = mini_batch_utils.sample_avod_mini_batch(
                max_ious)
            mb_class_label_indices = mini_batch_utils.mask_class_label_indices(
                mb_pos_mask, mb_mask, max_iou_indices, class_labels)

            mb_gt_indices = tf.boolean_mask(max_iou_indices, mb_mask)

        return mb_mask, mb_class_label_indices, mb_gt_indices
Ejemplo n.º 6
0
    def test_iou_mask_ops(self):
        # corners are in [y1, x1, y2, x2] format
        corners_pred = tf.constant(
            [[4.0, 3.0, 7.0, 5.0],
             [14.0, 14.0, 16.0, 16.0],
             [0.0, 0.0, 21.0, 19.0],
             [3.0, 4.0, 5.0, 7.0]])
        corners_gt = tf.constant(
            [[4.0, 3.0, 7.0, 6.0],
             [14.0, 14.0, 15.0, 15.0],
             [0.0, 0.0, 20.0, 20.0]])
        # 3 classes
        class_indices = tf.constant([1., 2., 3.])

        exp_ious = [[0.66666669, 0., 0.02255639, 0.15384616],
                    [0., 0.25, 0.00250627, 0.],
                    [0.015, 0.01, 0.90692127, 0.015]]

        exp_max_ious = np.array([0.66666669, 0.25, 0.90692127, 0.15384616])
        exp_max_indices = np.array([0, 1, 2, 0])

        exp_pos_mask = np.array([True, False, True, False])

        exp_class_and_background_indices = np.array([1, 0, 3, 0])

        # Convert to box_list format
        boxes_pred = box_list.BoxList(corners_pred)
        boxes_gt = box_list.BoxList(corners_gt)
        # Calculate IoU
        iou = box_list_ops.iou(boxes_gt,
                               boxes_pred)

        # Get max IoU, the dimension should match the anchors we are
        # evaluating
        max_ious = tf.reduce_max(iou, axis=0)
        max_iou_indices = tf.argmax(iou, axis=0)

        # Sample a mini-batch from anchors with highest IoU match
        mini_batch_size = 4

        # Custom positive/negative iou ranges
        neg_2d_iou_range = [0.0, 0.3]
        pos_2d_iou_range = [0.6, 0.7]

        mb_mask, mb_pos_mask = \
            self.mb_utils.sample_mini_batch(max_ious,
                                            mini_batch_size,
                                            neg_2d_iou_range,
                                            pos_2d_iou_range)

        mb_class_indices = self.mb_utils.mask_class_label_indices(
            mb_pos_mask, mb_mask, max_iou_indices, class_indices)

        with self.test_session() as sess:
            iou_out = sess.run(iou)
            max_ious_out, max_iou_indices_out = sess.run([max_ious,
                                                          max_iou_indices])
            mb_mask_out, mb_pos_mask_out = sess.run([mb_mask,
                                                     mb_pos_mask])
            class_indices_out = sess.run(mb_class_indices)

            self.assertAllClose(iou_out, exp_ious)
            self.assertAllClose(max_ious_out, exp_max_ious)
            self.assertAllEqual(max_iou_indices_out, exp_max_indices)
            self.assertAllEqual(exp_pos_mask, mb_pos_mask_out)
            self.assertAllEqual(class_indices_out,
                                exp_class_and_background_indices)