def batch_dice_loss(inputs, targets):
    """
    Compute the DICE loss, similar to generalized IOU for masks
    Args:
        inputs: A float tensor of arbitrary shape.
                The predictions for each example.
        targets: A float tensor with the same shape as inputs. Stores the binary
                 classification label for each element in inputs
                (0 for the negative class and 1 for the positive class).
    """
    inputs = F.sigmoid(inputs)
    inputs = paddle.flatten(inputs, start_axis=1)
    numerator = 2 * paddle.einsum("nc,mc->nm", inputs, targets)
    denominator = paddle.sum(inputs, axis=-1, keepdim=True) + paddle.sum(
        targets, axis=-1).unsqueeze(0)
    loss = 1 - (numerator + 1) / (denominator + 1)
    return loss

    Compute the DICE loss, similar to generalized IOU for masks
    Args:
        inputs: A float tensor of arbitrary shape.
                The predictions for each example.
        targets: A float tensor with the same shape as inputs. Stores the binary
                 classification label for each element in inputs
                (0 for the negative class and 1 for the positive class).
    
paddleseg/models/losses/maskformer_loss.py