models/deformable_detr.py
def loss_labels(self, outputs, targets, indices, num_boxes, log=True):
        """Classification loss (NLL)
        targets dicts must contain the key "labels" containing a tensor of dim [nb_target_boxes]
        """
        assert 'pred_logits' in outputs
        src_logits = outputs['pred_logits']

        idx = self._get_src_permutation_idx(indices)
        target_classes_o = torch.cat([t["labels"][J] for t, (_, J) in zip(targets, indices)])
        target_classes = torch.full(src_logits.shape[:2], self.num_classes,
                                    dtype=torch.int64, device=src_logits.device)
        target_classes[idx] = target_classes_o

        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_ce = sigmoid_focal_loss(src_logits, target_classes_onehot, num_boxes, alpha=self.focal_alpha, gamma=2) * src_logits.shape[1]
        losses = {'loss_ce': loss_ce}

        if log:
            # TODO this should probably be a separate loss, not hacked in this one here
            losses['class_error'] = 100 - accuracy(src_logits[idx], target_classes_o)[0]
        return losses
Classification loss (NLL)
        targets dicts must contain the key "labels" containing a tensor of dim [nb_target_boxes]
        
Classification loss (NLL)
targets dicts must contain the key "labels" containing a tensor of dim [nb_target_boxes]
Classification loss ( NLL ) targets dicts must contain the key " labels " containing a tensor of dim [ nb_target_boxes ]
def loss_labels(self, outputs, targets, indices, num_boxes, log=True):
        assert 'pred_logits' in outputs
        src_logits = outputs['pred_logits']
        idx = self._get_src_permutation_idx(indices)
        target_classes_o = torch.cat([t["labels"][J] for t, (_, J) in zip(targets, indices)])
        target_classes = torch.full(src_logits.shape[:2], self.num_classes,
                                    dtype=torch.int64, device=src_logits.device)
        target_classes[idx] = target_classes_o
        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_ce = sigmoid_focal_loss(src_logits, target_classes_onehot, num_boxes, alpha=self.focal_alpha, gamma=2) * src_logits.shape[1]
        losses = {'loss_ce': loss_ce}
        if log:
            losses['class_error'] = 100 - accuracy(src_logits[idx], target_classes_o)[0]
        return losses
def loss_labels ( self , outputs , targets , indices , num_boxes , log = True ) : assert 'pred_logits' in outputs src_logits = outputs [ 'pred_logits' ] idx = self . _get_src_permutation_idx ( indices ) target_classes_o = torch . cat ( [ t [ "labels" ] [ J ] for t , ( _ , J ) in zip ( targets , indices ) ] ) target_classes = torch . full ( src_logits . shape [ : 2 ] , self . num_classes , dtype = torch . int64 , device = src_logits . device ) target_classes [ idx ] = target_classes_o 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_ce = sigmoid_focal_loss ( src_logits , target_classes_onehot , num_boxes , alpha = self . focal_alpha , gamma = 2 ) * src_logits . shape [ 1 ] losses = { 'loss_ce' : loss_ce } if log : losses [ 'class_error' ] = 100 - accuracy ( src_logits [ idx ] , target_classes_o ) [ 0 ] return losses
Classification loss (NLL)
targets dicts must contain the key "labels" containing a tensor of dim [nb_target_boxes]
Classification loss ( NLL ) targets dicts must contain the key " labels " containing a tensor of dim [ nb_target_boxes ]
"""Classification loss (NLL)
        targets dicts must contain the key "labels" containing a tensor of dim [nb_target_boxes]
        """ # TODO this should probably be a separate loss, not hacked in this one here
self
outputs
targets
indices
num_boxes
log