import torch


def calculate_iou(pred_vol: torch.Tensor, gt_vol: torch.Tensor) -> torch.Tensor:
    """
        Cacluate Intersection-over-Union Score
    :param pred_vol: Predicted volume, shape: [B, N_VOX (32), N_VOX (32), N_VOX (32)]
    :param gt_vol: Ground-truth volume, shape: [B, N_VOX (32), N_VOX (32), N_VOX (32)]
    :return: IoU Score, scalar
    """
    dims = [1, 2, 3]
    intersection = (pred_vol * gt_vol).float().sum(dims)
    union = ((pred_vol + gt_vol) >= 1).float().sum(dims)
    return (intersection / union).mean()