API: Metrics & helpers
The metrics take probabilities of shape (B, C, *spatial) and integer labels of
shape (B, *spatial), with optional mask and ignore_index.
negative_log_likelihood
negative_log_likelihood(probs: Any, targets: Any, mask: Any | None = None, ignore_index: int = -100) -> float
Mean negative log-likelihood (cross-entropy) over valid voxels.
Source code in src/fiducio/metrics/calibration.py
expected_calibration_error
expected_calibration_error(probs: Any, targets: Any, mask: Any | None = None, ignore_index: int = -100, n_bins: int = 15) -> float
Top-1 expected calibration error (ECE) with uniform binning.
The confidence is the maximum predicted probability and the accuracy is
whether the argmax matches the label. Bins partition [0, 1] uniformly
and each bin's gap is weighted by its share of voxels — see
:func:average_calibration_error for the unweighted variant.
n_bins defaults to 15. The paper reports ECE with n_bins=50 (ACE with
n_bins=15) and averages metrics per image before pooling; pass
n_bins=50 and compute per case to follow that convention. Boundary-aware
ECE is not included.
Source code in src/fiducio/metrics/calibration.py
average_calibration_error
average_calibration_error(probs: Any, targets: Any, mask: Any | None = None, ignore_index: int = -100, n_bins: int = 15) -> float
Top-1 average calibration error (ACE) with uniform binning.
Uses the same uniform confidence bins as :func:expected_calibration_error,
but averages the per-bin |confidence - accuracy| gap unweighted
over non-empty bins instead of weighting each bin by its share of voxels.
A confidence region visited by only a handful of voxels therefore counts as
much as a densely populated one, which ECE would otherwise drown out.
n_bins=15 matches the paper's ACE; the paper computes ACE on the pooled
test voxels rather than per image.
Source code in src/fiducio/metrics/calibration.py
brier_score
Mean multiclass Brier score over valid voxels.
Source code in src/fiducio/metrics/calibration.py
reliability_curve
reliability_curve(probs: Any, targets: Any, mask: Any | None = None, ignore_index: int = -100, n_bins: int = 15) -> ReliabilityCurve
Compute top-1 reliability statistics with uniform binning.
The confidence is the maximum predicted probability and the accuracy is
whether the argmax matches the label. Useful both for reporting ECE/ACE and
for drawing reliability diagrams (see
:func:fiducio.plots.reliability_diagram).
Source code in src/fiducio/metrics/calibration.py
ReliabilityCurve
dataclass
ReliabilityCurve(bin_edges: Tensor, bin_confidence: Tensor, bin_accuracy: Tensor, bin_counts: Tensor, ece: float, ace: float)
Per-bin reliability statistics from top-1 confidence binning.
Attributes:
| Name | Type | Description |
|---|---|---|
bin_edges |
Tensor
|
|
bin_confidence |
Tensor
|
|
bin_accuracy |
Tensor
|
|
bin_counts |
Tensor
|
|
ece |
float
|
Expected calibration error (count-weighted mean |
ace |
float
|
Average calibration error (unweighted mean |
Helpers
two_channel_from_binary
Convert single-channel binary outputs to the two-channel form Fiducio uses.
Fiducio represents binary segmentation as two channels (C = 2). Use this
helper to convert a single-channel sigmoid output, whose class axis at
dimension 1 has size 1 (shape (B, 1, *spatial)), into (B, 2, *spatial).
Class 1 is the positive class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores
|
ArrayLike
|
|
required |
input_type
|
str
|
|
'logits'
|
Source code in src/fiducio/utils/tensors.py
get_calibrator_class
Return the calibrator class registered under calibrator_id.