Translocations_Detector/models/detr.py
def loss_segments(self, outputs, targets, indices, num_segments):
        """Compute the losses related to the bounding segments, the L1 regression loss and the GIoU loss
           targets dicts must contain the key "segments" containing a tensor of dim [nb_target_segments, 2]
           The target segments are expected in format (center_x, w), normalized by the image size.
        """
        assert 'pred_segments' in outputs
        idx = self._get_src_permutation_idx(indices)
        src_segments = outputs['pred_segments'][idx]
        target_segments = torch.cat([t['segments'][i] for t, (_, i) in zip(targets, indices)], dim=0)

        loss_bsegment = F.l1_loss(src_segments, target_segments, reduction='none')

        losses = {}
        losses['loss_bsegment'] = loss_bsegment.sum() / num_segments

        loss_giou = 1 - torch.diag(seg_ops.generalized_seg_iou(
            seg_ops.seg_cxw_to_x0x1(seg_ops.seg_bxw_to_cxw(src_segments)),
            seg_ops.seg_cxw_to_x0x1(seg_ops.seg_bxw_to_cxw(target_segments))))
        losses['loss_giou'] = loss_giou.sum() / num_segments
        return losses
Compute the losses related to the bounding segments, the L1 regression loss and the GIoU loss
           targets dicts must contain the key "segments" containing a tensor of dim [nb_target_segments, 2]
           The target segments are expected in format (center_x, w), normalized by the image size.
        
Compute the losses related to the bounding segments, the L1 regression loss and the GIoU loss
targets dicts must contain the key "segments" containing a tensor of dim [nb_target_segments, 2]
The target segments are expected in format (center_x, w), normalized by the image size.
Compute the losses related to the bounding segments the L1 regression loss and the GIoU loss targets dicts must contain the key " segments " containing a tensor of dim [ nb_target_segments 2 ] The target segments are expected in format ( center_x w ) normalized by the image size .
def loss_segments(self, outputs, targets, indices, num_segments):
        assert 'pred_segments' in outputs
        idx = self._get_src_permutation_idx(indices)
        src_segments = outputs['pred_segments'][idx]
        target_segments = torch.cat([t['segments'][i] for t, (_, i) in zip(targets, indices)], dim=0)
        loss_bsegment = F.l1_loss(src_segments, target_segments, reduction='none')
        losses = {}
        losses['loss_bsegment'] = loss_bsegment.sum() / num_segments
        loss_giou = 1 - torch.diag(seg_ops.generalized_seg_iou(
            seg_ops.seg_cxw_to_x0x1(seg_ops.seg_bxw_to_cxw(src_segments)),
            seg_ops.seg_cxw_to_x0x1(seg_ops.seg_bxw_to_cxw(target_segments))))
        losses['loss_giou'] = loss_giou.sum() / num_segments
        return losses
def loss_segments ( self , outputs , targets , indices , num_segments ) : assert 'pred_segments' in outputs idx = self . _get_src_permutation_idx ( indices ) src_segments = outputs [ 'pred_segments' ] [ idx ] target_segments = torch . cat ( [ t [ 'segments' ] [ i ] for t , ( _ , i ) in zip ( targets , indices ) ] , dim = 0 ) loss_bsegment = F . l1_loss ( src_segments , target_segments , reduction = 'none' ) losses = { } losses [ 'loss_bsegment' ] = loss_bsegment . sum ( ) / num_segments loss_giou = 1 - torch . diag ( seg_ops . generalized_seg_iou ( seg_ops . seg_cxw_to_x0x1 ( seg_ops . seg_bxw_to_cxw ( src_segments ) ) , seg_ops . seg_cxw_to_x0x1 ( seg_ops . seg_bxw_to_cxw ( target_segments ) ) ) ) losses [ 'loss_giou' ] = loss_giou . sum ( ) / num_segments return losses
Compute the losses related to the bounding segments, the L1 regression loss and the GIoU loss
targets dicts must contain the key "segments" containing a tensor of dim [nb_target_segments, 2]
The target segments are expected in format (center_x, w), normalized by the image size.
Compute the losses related to the bounding segments the L1 regression loss and the GIoU loss targets dicts must contain the key " segments " containing a tensor of dim [ nb_target_segments 2 ] The target segments are expected in format ( center_x w ) normalized by the image size .
"""Compute the losses related to the bounding segments, the L1 regression loss and the GIoU loss
           targets dicts must contain the key "segments" containing a tensor of dim [nb_target_segments, 2]
           The target segments are expected in format (center_x, w), normalized by the image size.
        """
self
outputs
targets
indices
num_segments