Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weighting of DIOU/ CIOU loss #21

Open
AhmedMagdyHendawy opened this issue Feb 10, 2021 · 1 comment
Open

Weighting of DIOU/ CIOU loss #21

AhmedMagdyHendawy opened this issue Feb 10, 2021 · 1 comment

Comments

@AhmedMagdyHendawy
Copy link

AhmedMagdyHendawy commented Feb 10, 2021

Hello,
Could you please explain why did you normalize the loss at the end by both:

  • bbox_outside_weights
  • output.size(0)
    ?

iou_weights = bbox_inside_weights.view(-1, 4).mean(1) * bbox_outside_weights.view(-1, 4).mean(1)
iouk = ((1 - iouk) * iou_weights).sum(0) / output.size(0)
diouk = ((1 - diouk)).sum(0)

What I can understand from the whole source code that each of the bbox_outside_weights components is 1/num_examples as in

# Bbox regression loss has the form:
#   loss(x) = weight_outside * L(weight_inside * x)
# Inside weights allow us to set zero loss on an element-wise basis
# Bbox regression is only trained on positive examples so we set their
# weights to 1.0 (or otherwise if config is different) and 0 otherwise
bbox_inside_weights = np.zeros((num_inside, 4), dtype=np.float32)
bbox_inside_weights[labels == 1, :] = (1.0, 1.0, 1.0, 1.0)

# The bbox regression loss only averages by the number of images in the
# mini-batch, whereas we need to average by the total number of example
# anchors selected
# Outside weights are used to scale each element-wise loss so the final
# average over the mini-batch is correct
bbox_outside_weights = np.zeros((num_inside, 4), dtype=np.float32)
# uniform weighting of examples (given non-uniform sampling)
num_examples = np.sum(labels >= 0)
bbox_outside_weights[labels == 1, :] = 1.0 / num_examples
bbox_outside_weights[labels == 0, :] = 1.0 / num_examples

in /lib/roi_data/rpn.py

@AhmedMagdyHendawy
Copy link
Author

Is it another kind of scaling for the loss?

bbox_outside_weights[labels == 1, :] = 1.0 / num_examples
bbox_outside_weights[labels == 0, :] = 1.0 / num_examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant