Skip to content

About the RPN loss (smooth_L1_LOSS) #197

@hehualin-tut

Description

@hehualin-tut

`class WeightedSmoothL1Loss(Loss):
"""Smooth L1 localization loss function.
The smooth L1_loss is defined elementwise as .5 x^2 if |x|<1 and |x|-.5
otherwise, where x is the difference between predictions and target.
See also Equation (3) in the Fast R-CNN paper by Ross Girshick (ICCV 2015)
"""

def _compute_loss(self, prediction_tensor, target_tensor, weight):
    """Compute loss function.
    Args:
        prediction_tensor: A float tensor of shape [num_anchors,
            code_size] representing the (encoded) predicted
            locations of objects.
        target_tensor: A float tensor of shape [num_anchors,
            code_size] representing the regression targets
    Returns:
      loss: an anchorwise tensor of shape [num_anchors] representing
        the value of the loss function
    """
    diff = prediction_tensor - target_tensor
    abs_diff = tf.abs(diff)
    abs_diff_lt_1 = tf.less(abs_diff, 1)

    anchorwise_smooth_l1norm = tf.reduce_sum(
        tf.where(abs_diff_lt_1, 0.5 * tf.square(abs_diff), abs_diff - 0.5),
        axis=1) * weight
    return anchorwise_smooth_l1norm`

Question:
Could u tell me What is the dimension of this “code_size” in the prediction_tensor and target_tensor?
I want to use Giou loss to replace the Initial L1 loss function, I SAW this "boxes_4c: (N, 10) [x1, x2, x3, x4, z1, z2, z3, z4, h1, h2]" in the wiki, SO the prediction_tensor and target_tensor is [N,10] ? Am I wrong? I created the loss function based on 10 dimensions.Can you help me see if that's right?

Ap=(prediction_tensor[:, 0]-prediction_tensor[:, 2])(prediction_tensor[:, 4]-prediction_tensor[:, 6])(prediction_tensor[:, 9]-prediction_tensor[:, 8])#the volume of the Predicted box
Ag=(target_tensor[:, 0]-target_tensor[:, 2])(target_tensor[:, 4]-target_tensor[:, 6])(target_tensor[:, 9]-target_tensor[:, 8])#the volume of the gt box
x1=tf.maximum(prediction_tensor,target_tensor,name=None)
x2=tf.minimum(prediction_tensor,target_tensor,name=None)
I=(x2[:, 0]-x1[:, 2])(x2[:, 4]-x1[:, 6])(x2[:, 9]-x1[:, 8])#Two BOX coincident partial volume calculations
Ac=(x1[:, 0]-x2[:, 2])(x1[:, 4]-x2[:, 6])(x1[:, 9]-x2[:, 8])#The minimum bracketing volume of two boxes is calculated
U=Ap+Ag-I
IOU=I/U#IOU
GIOU=IOU-((Ac-U)/Ac)#GIOU
anchorwise_smooth_l1norm=(1-GIOU)*weight#loss
return anchorwise_smooth_l1norm

If I'm not right, do you know how to fix it?I would be very grateful if you could give me some advice.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions