IDEA-Research / DINO

[ICLR 2023] Official implementation of the paper "DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection"
Apache License 2.0
2.15k stars 232 forks source link

can't find negative loss in CDN #119

Closed Vallum closed 1 year ago

Vallum commented 1 year ago

Dear authors, Thank you for opening the fantastic project!

BTW, I am wondering where I can find the negative loss of CDN. I could see that you used the only positive cases for losses at https://github.com/IDEA-Research/DINO/blob/f7262ddcbc5a9fcf4cd2ac9924cee37cdb459a05/models/dino/dino.py#L518

        if self.training and dn_meta and 'output_known_lbs_bboxes' in dn_meta:
            output_known_lbs_bboxes,single_pad, scalar = self.prep_for_dn(dn_meta)

            dn_pos_idx = []
            dn_neg_idx = []
            for i in range(len(targets)):
                if len(targets[i]['labels']) > 0:
                    t = torch.range(0, len(targets[i]['labels']) - 1).long().cuda()
                    t = t.unsqueeze(0).repeat(scalar, 1)
                    tgt_idx = t.flatten()
                    output_idx = (torch.tensor(range(scalar)) * single_pad).long().cuda().unsqueeze(1) + t
                    output_idx = output_idx.flatten()
                else:
                    output_idx = tgt_idx = torch.tensor([]).long().cuda()

                dn_pos_idx.append((output_idx, tgt_idx))
                dn_neg_idx.append((output_idx + single_pad // 2, tgt_idx))

            output_known_lbs_bboxes=dn_meta['output_known_lbs_bboxes']
            l_dict = {}
            for loss in self.losses:
                kwargs = {}
                if 'labels' in loss:
                    kwargs = {'log': False}
                l_dict.update(self.get_loss(loss, output_known_lbs_bboxes, targets, dn_pos_idx, num_boxes*scalar,**kwargs))

But it seems like you used only 'dn_pos_idx'. In that case, DN-DETR and DINO look like same to me without MQS and LFT.

What did I miss?

HaoZhang534 commented 1 year ago

The label loss contains loss for negative samples. It will classify any predictions that are not matched with gt as "no object".