Vision metrics
calculate_dsc
calculate_dsc (pred:torch.Tensor, targ:torch.Tensor)
MONAI compute_meandice
calculate_haus
calculate_haus (pred:torch.Tensor, targ:torch.Tensor)
Compute 95th percentile Hausdorff distance (HD95) using MONAI.
HD95 is more robust than standard Hausdorff distance as it ignores the top 5% of outlier distances.
Args: pred: Binary prediction tensor [B, C, W, H, D]. targ: Binary target tensor [B, C, W, H, D].
Returns: HD95 values for each sample in batch.
binary_dice_score
binary_dice_score (act:<built- inmethodtensoroftypeobjectat0x7f0db213ecc0>, targ:torch.Tensor)
Calculates the mean Dice score for binary semantic segmentation tasks.
Args: act: Activation tensor with dimensions [B, C, W, H, D]. targ: Target masks with dimensions [B, C, W, H, D].
Returns: Mean Dice score.
multi_dice_score
multi_dice_score (act:torch.Tensor, targ:torch.Tensor)
Calculate the mean Dice score for each class in multi-class semantic segmentation tasks.
Args: act: Activation tensor with dimensions [B, C, W, H, D]. targ: Target masks with dimensions [B, C, W, H, D].
Returns: Mean Dice score for each class.
binary_hausdorff_distance
binary_hausdorff_distance (act:torch.Tensor, targ:torch.Tensor)
Calculate the mean HD95 for binary semantic segmentation tasks.
Args: act: Activation tensor with dimensions [B, C, W, H, D]. targ: Target masks with dimensions [B, C, W, H, D].
Returns: Mean HD95.
multi_hausdorff_distance
multi_hausdorff_distance (act:torch.Tensor, targ:torch.Tensor)
Calculate the mean HD95 for each class in multi-class semantic segmentation tasks.
Args: act: Activation tensor with dimensions [B, C, W, H, D]. targ: Target masks with dimensions [B, C, W, H, D].
Returns: Mean HD95 for each class.
Sensitivity and Precision
calculate_confusion_metrics
calculate_confusion_metrics (pred:torch.Tensor, targ:torch.Tensor, metric_name:str)
Calculate confusion matrix-based metric using MONAI.
Args: pred: Binary prediction tensor [B, C, W, H, D]. targ: Binary target tensor [B, C, W, H, D]. metric_name: One of “sensitivity”, “precision”, “specificity”, “f1 score”.
Returns: Metric values for each sample in batch.
binary_sensitivity
binary_sensitivity (act:torch.Tensor, targ:torch.Tensor)
Calculate mean sensitivity (recall) for binary segmentation.
Sensitivity = TP / (TP + FN) - measures the proportion of actual positives that are correctly identified.
Args: act: Activation tensor [B, C, W, H, D]. targ: Target masks [B, C, W, H, D].
Returns: Mean sensitivity score.
multi_sensitivity
multi_sensitivity (act:torch.Tensor, targ:torch.Tensor)
Calculate mean sensitivity for each class in multi-class segmentation.
Args: act: Activation tensor [B, C, W, H, D]. targ: Target masks [B, C, W, H, D].
Returns: Mean sensitivity for each class.
binary_precision
binary_precision (act:torch.Tensor, targ:torch.Tensor)
Calculate mean precision for binary segmentation.
Precision = TP / (TP + FP) - measures the proportion of positive predictions that are actually correct.
Args: act: Activation tensor [B, C, W, H, D]. targ: Target masks [B, C, W, H, D].
Returns: Mean precision score.
multi_precision
multi_precision (act:torch.Tensor, targ:torch.Tensor)
Calculate mean precision for each class in multi-class segmentation.
Args: act: Activation tensor [B, C, W, H, D]. targ: Target masks [B, C, W, H, D].
Returns: Mean precision for each class.
Lesion Detection Rate
calculate_lesion_detection_rate
calculate_lesion_detection_rate (pred:torch.Tensor, targ:torch.Tensor)
Calculate lesion-wise detection rate.
For each connected component (lesion) in the target, check if there is any overlap with the prediction. A lesion is considered detected if at least one voxel overlaps.
Args: pred: Binary prediction tensor [B, C, W, H, D]. targ: Binary target tensor [B, C, W, H, D].
Returns: Detection rate (detected lesions / total lesions) for each sample.
binary_lesion_detection_rate
binary_lesion_detection_rate (act:torch.Tensor, targ:torch.Tensor)
Calculate mean lesion detection rate for binary segmentation.
Args: act: Activation tensor [B, C, W, H, D]. targ: Target masks [B, C, W, H, D].
Returns: Mean lesion detection rate.
multi_lesion_detection_rate
multi_lesion_detection_rate (act:torch.Tensor, targ:torch.Tensor)
Calculate mean lesion detection rate for each class in multi-class segmentation.
Args: act: Activation tensor [B, C, W, H, D]. targ: Target masks [B, C, W, H, D].
Returns: Mean lesion detection rate for each class.
Signed Relative Volume Error (RVE)
calculate_signed_rve
calculate_signed_rve (pred:torch.Tensor, targ:torch.Tensor)
Calculate signed Relative Volume Error.
RVE = (pred_volume - targ_volume) / targ_volume
Positive values indicate over-segmentation (model predicts too large), negative values indicate under-segmentation (model predicts too small).
Args: pred: Binary prediction tensor [B, C, W, H, D]. targ: Binary target tensor [B, C, W, H, D].
Returns: Signed RVE for each sample in batch.
binary_signed_rve
binary_signed_rve (act:torch.Tensor, targ:torch.Tensor)
Calculate mean signed RVE for binary segmentation.
Args: act: Activation tensor [B, C, W, H, D]. targ: Target masks [B, C, W, H, D].
Returns: Mean signed RVE.
multi_signed_rve
multi_signed_rve (act:torch.Tensor, targ:torch.Tensor)
Calculate mean signed RVE for each class in multi-class segmentation.
Args: act: Activation tensor [B, C, W, H, D]. targ: Target masks [B, C, W, H, D].
Returns: Mean signed RVE for each class.