def split_proposals(proposals, proposals_num, gt, gt_num, iou, scores, cross_boundary_mask):
'''Generate batches from proposals and ground truth boxes
Idea is to drastically reduce number of proposals to evaluate. So, we find those
proposals that have IoU > 0.7 with _any_ ground truth and mark them as positive samples.
Proposals with IoU < 0.3 with _all_ ground truth boxes are considered negative. All
other proposals are discarded.
We generate batch with at most half of examples being positive. We also pad them with negative
have we not enough positive proposals.
proposals: N x 4 tensor
proposal_num: N
gt: M x 4 tensor
gt_num: M
iou: N x M tensor of IoU between every proposal and ground truth
scores: N x 2 tensor with scores object/not-object
cross_boundary_mask: N x 1 Tensor masking out-of-image proposals
'''
# now let's get rid of non-positive and non-negative samples
# Sample is considered positive if it has IoU > 0.7 with _any_ ground truth box
# XXX: maximal IoU ground truth proposal should be treated as positive
positive_mask = tf.reduce_any(tf.greater(iou, 0.7), axis=1) & cross_boundary_mask
# Sample would be considered negative if _all_ ground truch box
# have iou less than 0.3
negative_mask = tf.reduce_all(tf.less(iou, 0.3), axis=1) & cross_boundary_mask
# Select only positive boxes and their corresponding predicted scores
positive_boxes = tf.boolean_mask(proposals, positive_mask)
positive_scores = tf.boolean_mask(scores, positive_mask)
positive_labels = tf.reduce_mean(tf.ones_like(positive_scores), axis=1)
# Same for negative
negative_boxes = tf.boolean_mask(proposals, negative_mask)
negative_scores = tf.boolean_mask(scores, negative_mask)
negative_labels = tf.reduce_mean(tf.zeros_like(negative_scores), axis=1)
return (
(positive_boxes, positive_scores, positive_labels),
(negative_boxes, negative_scores, negative_labels)
)
评论列表
文章目录