models/deformable_detr.py
def loss_masks(self, outputs, targets, indices, num_boxes):
        """Compute the losses related to the masks: the focal loss and the dice loss.
           targets dicts must contain the key "masks" containing a tensor of dim [nb_target_boxes, h, w]
        """
        assert "pred_masks" in outputs

        src_idx = self._get_src_permutation_idx(indices)
        tgt_idx = self._get_tgt_permutation_idx(indices)

        src_masks = outputs["pred_masks"]

        # TODO use valid to mask invalid areas due to padding in loss
        target_masks, valid = nested_tensor_from_tensor_list([t["masks"] for t in targets]).decompose()
        target_masks = target_masks.to(src_masks)

        src_masks = src_masks[src_idx]
        # upsample predictions to the target size
        src_masks = interpolate(src_masks[:, None], size=target_masks.shape[-2:],
                                mode="bilinear", align_corners=False)
        src_masks = src_masks[:, 0].flatten(1)

        target_masks = target_masks[tgt_idx].flatten(1)

        losses = {
            "loss_mask": sigmoid_focal_loss(src_masks, target_masks, num_boxes),
            "loss_dice": dice_loss(src_masks, target_masks, num_boxes),
        }
        return losses
Compute the losses related to the masks: the focal loss and the dice loss.
           targets dicts must contain the key "masks" containing a tensor of dim [nb_target_boxes, h, w]
        
Compute the losses related to the masks: the focal loss and the dice loss.
targets dicts must contain the key "masks" containing a tensor of dim [nb_target_boxes, h, w]
Compute the losses related to the masks : the focal loss and the dice loss . targets dicts must contain the key " masks " containing a tensor of dim [ nb_target_boxes h w ]
def loss_masks(self, outputs, targets, indices, num_boxes):
        assert "pred_masks" in outputs
        src_idx = self._get_src_permutation_idx(indices)
        tgt_idx = self._get_tgt_permutation_idx(indices)
        src_masks = outputs["pred_masks"]
        target_masks, valid = nested_tensor_from_tensor_list([t["masks"] for t in targets]).decompose()
        target_masks = target_masks.to(src_masks)
        src_masks = src_masks[src_idx]
        src_masks = interpolate(src_masks[:, None], size=target_masks.shape[-2:],
                                mode="bilinear", align_corners=False)
        src_masks = src_masks[:, 0].flatten(1)
        target_masks = target_masks[tgt_idx].flatten(1)
        losses = {
            "loss_mask": sigmoid_focal_loss(src_masks, target_masks, num_boxes),
            "loss_dice": dice_loss(src_masks, target_masks, num_boxes),
        }
        return losses
def loss_masks ( self , outputs , targets , indices , num_boxes ) : assert "pred_masks" in outputs src_idx = self . _get_src_permutation_idx ( indices ) tgt_idx = self . _get_tgt_permutation_idx ( indices ) src_masks = outputs [ "pred_masks" ] target_masks , valid = nested_tensor_from_tensor_list ( [ t [ "masks" ] for t in targets ] ) . decompose ( ) target_masks = target_masks . to ( src_masks ) src_masks = src_masks [ src_idx ] src_masks = interpolate ( src_masks [ : , None ] , size = target_masks . shape [ - 2 : ] , mode = "bilinear" , align_corners = False ) src_masks = src_masks [ : , 0 ] . flatten ( 1 ) target_masks = target_masks [ tgt_idx ] . flatten ( 1 ) losses = { "loss_mask" : sigmoid_focal_loss ( src_masks , target_masks , num_boxes ) , "loss_dice" : dice_loss ( src_masks , target_masks , num_boxes ) , } return losses
Compute the losses related to the masks: the focal loss and the dice loss.
Compute the losses related to the masks : the focal loss and the dice loss .
"""Compute the losses related to the masks: the focal loss and the dice loss.
           targets dicts must contain the key "masks" containing a tensor of dim [nb_target_boxes, h, w]
        """ # TODO use valid to mask invalid areas due to padding in loss # upsample predictions to the target size
self
outputs
targets
indices
num_boxes