损失函数分为框预测回归和分类loss,每个都分为rpn和rcnn。
rpn损失:
_anchor_target_layer 给图像内部的anchors分配rpn_labels(1或0,前景或背景),再和rpn_cls_score做交叉熵,此时只关注物体是前景/背景,不管物体的类别
rpn_cross_entropy = tf.reduce_mean(
tf.nn.sparse_softmax_cross_entropy_with_logits(logits=rpn_cls_score, labels=rpn_label))
对图像内部的框做回归
# 计算anchor平移和放缩的幅度target,和所属的类比较
bbox_targets = _compute_targets(anchors, gt_boxes[argmax_overlaps, :])
......
# bbox_targets
bbox_targets = bbox_targets \
.reshape((1, height, width, A * 4))
rpn_bbox_targets = bbox_targets
rpn_loss_box = self._smooth_l1_loss(rpn_bbox_pred, rpn_bbox_targets, rpn_bbox_inside_weights,
rpn_bbox_outside_weights, sigma=sigma_rpn, dim=[1, 2, 3])