wjun0830 / QD-DETR

Official pytorch repository for "QD-DETR : Query-Dependent Video Representation for Moment Retrieval and Highlight Detection" (CVPR 2023 Paper)
https://arxiv.org/abs/2303.13874
Other
207 stars 16 forks source link

The implement of rank-aware contrastive loss #21

Closed KonataMyLove closed 1 year ago

KonataMyLove commented 1 year ago

Thank you for your open-source code. Here I have a question about the code of rank-aware contrastive loss metioned in the Section3.4 of the paper:

This is the rank-aware contrastive loss formula listed in the paper, 图片

This is the code of rank-aware contrastive loss computation in the qd_detr/model.py:

softmax

        exp_logits = torch.exp(logits)
        **log_prob = logits - torch.log(exp_logits.sum(1, keepdim=True) + 1e-6)**
        mean_log_prob_pos = (pos_mask * log_prob * vid_token_mask).sum(1) / (pos_mask.sum(1) + 1e-6)
        loss = - mean_log_prob_pos * batch_drop_mask
        loss_rank_contrastive = loss_rank_contrastive + loss.mean()

I don't think the code implement matched the formula? Especially the bolded code makes me confused. If I get it wrong, please inform me. Thank you for your time.

wjun0830 commented 1 year ago

For the contrastive equation and the implementation, you can find descriptions in supervised contrastive Learning paper and repository. For the rank, there is a for loop to implement it.

KonataMyLove commented 1 year ago

Thanks. I rewrote the formula according to the repository and the code, it does match the paper. Problem solved.