Translocations_Detector/models/detr.py
def loss_labels(self, outputs, targets, indices, num_segments, log=True):
      """Classification loss (NLL)
      targets dicts must contain the key "labels" containing a tensor of dim [nb_target_segments]
      """
      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)]).long()
      target_classes = torch.full(src_logits.shape[:2], self.num_classes,
                                  dtype=torch.int64, device=src_logits.device)
      target_classes[idx] = target_classes_o

      loss_ce = F.cross_entropy(src_logits.transpose(1, 2), target_classes, self.empty_weight)
      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_segments]
      
Classification loss (NLL)
targets dicts must contain the key "labels" containing a tensor of dim [nb_target_segments]
Classification loss ( NLL ) targets dicts must contain the key " labels " containing a tensor of dim [ nb_target_segments ]
def loss_labels(self, outputs, targets, indices, num_segments, 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)]).long()
      target_classes = torch.full(src_logits.shape[:2], self.num_classes,
                                  dtype=torch.int64, device=src_logits.device)
      target_classes[idx] = target_classes_o
      loss_ce = F.cross_entropy(src_logits.transpose(1, 2), target_classes, self.empty_weight)
      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_segments , 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 ) ] ) . long ( ) target_classes = torch . full ( src_logits . shape [ : 2 ] , self . num_classes , dtype = torch . int64 , device = src_logits . device ) target_classes [ idx ] = target_classes_o loss_ce = F . cross_entropy ( src_logits . transpose ( 1 , 2 ) , target_classes , self . empty_weight ) 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_segments]
Classification loss ( NLL ) targets dicts must contain the key " labels " containing a tensor of dim [ nb_target_segments ]
"""Classification loss (NLL)
      targets dicts must contain the key "labels" containing a tensor of dim [nb_target_segments]
      """ # TODO this should probably be a separate loss, not hacked in this one here
self
outputs
targets
indices
num_segments
log