fg_inds_size = tf.size(fg_inds)
// Condition for check if we have too many positive labels.
subsample_positive_cond = (
tf.to_int32(fg_inds_size) > tf.to_int32(num_fg))
// Check the condition and subsample positive labels.
labels = tf.cond(
subsample_positive_cond,
After Change
x=tf.to_float(tf.fill(tf.shape(labels), -1)), y=labels
)
num_bg = tf.to_int32(self._minibatch_size - fg_inds_size)
// Get background indices, get True in the indices where we have a cero.
bg_inds = tf.equal(labels, 0)
// We get only the indices where we have True.
bg_inds = tf.squeeze(tf.where(bg_inds), axis=1)
bg_inds_size = tf.size(bg_inds)
// Condition for check if we have too many positive labels.
subsample_negative_cond = bg_inds_size > num_bg
// Check the condition and subsample positive labels.
labels = tf.cond(
subsample_negative_cond,
true_fn=subsample_negative, false_fn=lambda: labels
)
// Returns bbox targets with shape (anchors.shape[0], 4)
// Find the closest gt box for each anchor.
argmax_overlaps = tf.argmax(overlaps, axis=1)
// Eliminate duplicates.
argmax_overlaps_unique, _ = tf.unique(argmax_overlaps)
// Filter the gt_boxes.
// We get only the indices where we have "inside anchors".
anchor_filter_inds = tf.where(anchor_filter)
gt_boxes = tf.gather(gt_boxes, argmax_overlaps)
bbox_targets = encode_tf(anchors, gt_boxes)
// For the anchors that arent foreground, we ignore the bbox_targets
anchor_foreground_filter = tf.equal(labels, 1)
bbox_targets = tf.where(
condition=anchor_foreground_filter,
x=bbox_targets, y=tf.zeros_like(bbox_targets)
)