def loss_masks(self, outputs, targets, indices, num_masks):
        """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, "The 'pred_masks' need to be in outputs, but only got keys: {}".format(
            outputs.keys())

        targets_cpt, indices_cpt = [], []
        for t, indice in zip(targets, indices):
            if t['labels'].shape[0] != 0:
                targets_cpt.append(t)
                indices_cpt.append(indice)
        else:
            if indices_cpt == []:
                losses = {
                    "loss_mask": paddle.to_tensor([0.0]),
                    "loss_dice": paddle.to_tensor([0.0]),
                }
                return losses
        src_idx = self._get_src_permutation_idx(indices)
        tgt_idx = self._get_tgt_permutation_idx(indices_cpt)
        src_masks = outputs["pred_masks"]
        src_masks = src_masks[src_idx]
        if src_masks.ndim == 2:
            src_masks = src_masks.unsqueeze(0)
        masks = [t["masks"] for t in targets_cpt]

        target_masks, valid = nested_tensor_from_tensor_list(masks)
        target_masks = paddle.cast(target_masks, src_masks.dtype)
        target_masks = target_masks[tgt_idx]

        src_masks = F.interpolate(
            src_masks[:, None],
            size=target_masks.shape[-2:],
            mode="bilinear",
            align_corners=False)
        src_masks = paddle.flatten(src_masks[:, 0], 1)

        target_masks = paddle.flatten(target_masks, 1)
        target_masks = target_masks.reshape(src_masks.shape)
        losses = {
            "loss_mask": sigmoid_focal_loss(src_masks, target_masks, num_masks),
            "loss_dice": dice_loss(src_masks, target_masks, num_masks),
        }
        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]
        
paddleseg/models/losses/maskformer_loss.py