def rpn_rois(self, gt_boxes, labels):
self.proposals = tf.Print(self.proposals, [tf.shape(self.proposals)], message='proposal shape')
filled_gt_boxes = tf.concat(1, [tf.zeros([tf.shape(gt_boxes)[0], 1], dtype=tf.float32), gt_boxes])
all_rois = tf.concat(0, [self.proposals, filled_gt_boxes])
overlaps = self._calculate_overlaps(all_rois[:, 1:5], gt_boxes)
# because faster-rcnn process one image per batch, leave the num_images here to keep consistency.
num_images = 1
rois_per_image = tf.constant(cfg.TRAIN.BATCH_SIZE / num_images, dtype=tf.float32)
fg_rois_per_image = tf.cast(tf.round(cfg.TRAIN.FG_FRACTION * rois_per_image), dtype=tf.int32)
gt_assignment = tf.arg_max(overlaps, dimension=1)
max_overlaps = tf.reduce_max(overlaps, reduction_indices=1)
labels = tf.gather(labels, gt_assignment)
fg_inds = tf.reshape(tf.cast(tf.where(max_overlaps >= cfg.TRAIN.FG_THRESH), dtype=tf.int32), [-1, ])
fg_rois_this_image = tf.minimum(fg_rois_per_image, tf.shape(fg_inds)[0])
# TODO: Check if fg_inds.size > 0:
fg_inds = tf.random_crop(fg_inds, size=[fg_rois_this_image])
bg_inds = tf.reshape(tf.cast(tf.where((max_overlaps < cfg.TRAIN.BG_THRESH_HI) &
(max_overlaps >= cfg.TRAIN.BG_THRESH_LO)),
dtype=tf.int32),
[-1, ])
bg_rois_this_image = tf.minimum(tf.cast(rois_per_image, dtype=tf.int32) - fg_rois_this_image, tf.shape(bg_inds)[0])
# TODO: Check if bg_inds.size > 0:
bg_inds = tf.random_crop(bg_inds, size=[bg_rois_this_image])
keep_inds = tf.concat(0, [fg_inds, bg_inds])
self.train_labels = tf.concat(0, (tf.gather(labels, fg_inds), tf.zeros((tf.shape(bg_inds)[0],), dtype=tf.int32)))
self.train_rois = tf.gather(all_rois, keep_inds)
bbox_target_data = self._compute_targets(
self.train_rois[:, 1:5], tf.gather(gt_boxes, tf.gather(gt_assignment, keep_inds)), self.train_labels)
return self.train_rois, self.train_labels, bbox_target_data
# TODO: implement this
# self.bbox_targets, self.bbox_inside_weights = \
# self._get_bbox_regression_labels(bbox_target_data, num_classes)
评论列表
文章目录