shenyunhang / DRN-WSOD-pytorch

Enabling Deep Residual Networks for Weakly Supervised Object Detection
https://github.com/shenyunhang/DRN-WSOD-pytorch/tree/DRN-WSOD/projects/WSL
Apache License 2.0
50 stars 10 forks source link

two return in roi_heads.py function #5

Closed CatOneTwo closed 3 years ago

CatOneTwo commented 3 years ago

Instructions To Reproduce the 🐛 Bug:

There is two return in roi_heads.py/_sample_proposals() function, I wonder does it a bug, or what does it mean?

Code Link

   def _sample_proposals(
        self, matched_idxs: torch.Tensor, matched_labels: torch.Tensor, gt_classes: torch.Tensor
    ) -> Tuple[torch.Tensor, torch.Tensor]:

        has_gt = gt_classes.numel() > 0
        # Get the corresponding GT for each proposal
        if has_gt:
            gt_classes = gt_classes[matched_idxs]
            # Label unmatched proposals (0 label from matcher) as background (label=num_classes)
            gt_classes[matched_labels == 0] = self.num_classes
            # Label ignore proposals (-1 label)
            gt_classes[matched_labels == -1] = -1
        else:
            gt_classes = torch.zeros_like(matched_idxs) + self.num_classes

        sampled_idxs = torch.arange(gt_classes.shape[0])
        return sampled_idxs, gt_classes[sampled_idxs]

        sampled_fg_idxs, sampled_bg_idxs = subsample_labels(
            gt_classes, self.batch_size_per_image, self.positive_fraction, self.num_classes
        )

        sampled_idxs = torch.cat([sampled_fg_idxs, sampled_bg_idxs], dim=0)
        return sampled_idxs, gt_classes[sampled_idxs]
shenyunhang commented 3 years ago

It is not a bug. This function is borrowed from the official detectron code, which generates a subset of proposals. Thus, we abandon this return by simply inserting a new return to keep all proposals.