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

Why there is a no_obj parameter? #19

Open
guanw-pku opened this issue Jan 12, 2023 · 1 comment
Open

Why there is a no_obj parameter? #19

guanw-pku opened this issue Jan 12, 2023 · 1 comment

Comments

@guanw-pku
Copy link

Thanks for this great work!

I noticed the loss functions adopted are dependent on no_obj. Could you please explain when no_obj is true and why the loss functions are dependent on it?

@cjw2021
Copy link
Owner

cjw2021 commented Feb 14, 2023

I'm sorry for the late reply.
Since we use the framework of Deformable DETR, we use the focal loss to set the matching cost of the object class in matcher.py and calculate the loss.

QAHOI/models/matcher.py

Lines 47 to 54 in 7eb19c5

if not self.no_obj:
alpha = 0.25
gamma = 2.0
neg_cost_class = (1 - alpha) * (out_obj_prob ** gamma) * (-(1 - out_obj_prob + 1e-8).log())
pos_cost_class = alpha * ((1 - out_obj_prob) ** gamma) * (-(out_obj_prob + 1e-8).log())
cost_obj_class = pos_cost_class[:, tgt_obj_labels] - neg_cost_class[:, tgt_obj_labels]
else:
cost_obj_class = -out_obj_prob[:, tgt_obj_labels]

QAHOI/models/QAHOI.py

Lines 257 to 265 in 7eb19c5

if not self.no_obj:
target_classes_onehot = torch.zeros([src_logits.shape[0], src_logits.shape[1], src_logits.shape[2] + 1],
dtype=src_logits.dtype, layout=src_logits.layout, device=src_logits.device)
target_classes_onehot.scatter_(2, target_classes.unsqueeze(-1), 1)
target_classes_onehot = target_classes_onehot[:,:,:-1]
loss_obj_ce = sigmoid_focal_loss(src_logits, target_classes_onehot, num_interactions, alpha=self.focal_alpha, gamma=2) * src_logits.shape[1]
else:
loss_obj_ce = F.cross_entropy(src_logits.transpose(1, 2), target_classes, self.empty_weight)

If using the same setting as DETR, which we call the "no_obj" setting, the matcher and loss will be the same as QPIC.

Since QAHOI uses 300 queries and in HICO-DET there are more negative results, the accuracy of setting "no_obj=False" is slightly higher.

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

2 participants