fusion_bench.metrics¶
NYUv2 Tasks¶
fusion_bench.metrics.nyuv2
¶
NYUv2 Dataset Metrics Module.
This module provides metric classes and loss functions for evaluating multi-task learning models on the NYUv2 dataset. NYUv2 is a popular indoor scene understanding dataset that includes multiple tasks: semantic segmentation, depth estimation, and surface normal prediction.
Available Metrics
- SegmentationMetric: Computes mIoU and pixel accuracy for semantic segmentation.
- DepthMetric: Computes absolute and relative errors for depth estimation.
- NormalMetric: Computes angular errors for surface normal prediction.
- NoiseMetric: Placeholder metric for noise evaluation.
Usage
from fusion_bench.metrics.nyuv2 import SegmentationMetric, DepthMetric
# Initialize metrics
seg_metric = SegmentationMetric(num_classes=13)
depth_metric = DepthMetric()
# Update with predictions and targets
seg_metric.update(seg_preds, seg_targets)
depth_metric.update(depth_preds, depth_targets)
# Compute final metrics
miou, pix_acc = seg_metric.compute()
abs_err, rel_err = depth_metric.compute()
metric_classes = {'segmentation': SegmentationMetric, 'depth': DepthMetric, 'normal': NormalMetric, 'noise': NoiseMetric}
module-attribute
¶
SegmentationMetric
¶
Bases: Metric
Metric for evaluating semantic segmentation on NYUv2 dataset.
This metric computes mean Intersection over Union (mIoU) and pixel accuracy for multi-class segmentation tasks.
Attributes:
-
metric_names–List of metric names ["mIoU", "pixAcc"].
-
num_classes–Number of segmentation classes (default: 13 for NYUv2).
-
record–Confusion matrix of shape (num_classes, num_classes) tracking predictions vs ground truth.
Source code in fusion_bench/metrics/nyuv2/segmentation.py
__init__(num_classes=13)
¶
Initialize the SegmentationMetric.
Parameters:
-
num_classes–Number of segmentation classes. Default is 13 for NYUv2 dataset.
Source code in fusion_bench/metrics/nyuv2/segmentation.py
compute()
¶
Compute mIoU and pixel accuracy from the confusion matrix.
Returns:
-
–
List[Tensor]: A list containing [mIoU, pixel_accuracy]: - mIoU: Mean Intersection over Union across all classes. - pixel_accuracy: Overall pixel classification accuracy.
Source code in fusion_bench/metrics/nyuv2/segmentation.py
reset()
¶
update(preds, target)
¶
Update the confusion matrix with predictions and targets from a batch.
Parameters:
-
preds(Tensor) –Predicted segmentation logits of shape (batch_size, num_classes, height, width). Will be converted to class predictions via softmax and argmax.
-
target(Tensor) –Ground truth segmentation labels of shape (batch_size, height, width). Pixels with negative values or values >= num_classes are ignored.
Source code in fusion_bench/metrics/nyuv2/segmentation.py
DepthMetric
¶
Bases: Metric
Metric for evaluating depth estimation performance on NYUv2 dataset.
This metric computes absolute error and relative error for depth predictions, properly handling the binary mask to exclude invalid depth regions.
Attributes:
-
metric_names–List of metric names ["abs_err", "rel_err"].
-
abs_record–List storing absolute error values for each batch.
-
rel_record–List storing relative error values for each batch.
-
batch_size–List storing batch sizes for weighted averaging.
Source code in fusion_bench/metrics/nyuv2/depth.py
__init__()
¶
Initialize the DepthMetric with state variables for tracking errors.
Source code in fusion_bench/metrics/nyuv2/depth.py
compute()
¶
Compute the final metric values across all batches.
Returns:
-
–
List[Tensor]: A list containing [absolute_error, relative_error], where each value is the weighted average across all batches.
Source code in fusion_bench/metrics/nyuv2/depth.py
reset()
¶
update(preds, target)
¶
Update metric states with predictions and targets from a batch.
Parameters:
-
preds(Tensor) –Predicted depth values of shape (batch_size, 1, height, width).
-
target(Tensor) –Ground truth depth values of shape (batch_size, 1, height, width). Pixels with sum of 0 are considered invalid and masked out.
Source code in fusion_bench/metrics/nyuv2/depth.py
NormalMetric
¶
Bases: Metric
Metric for evaluating surface normal prediction on NYUv2 dataset.
This metric computes angular error statistics between predicted and ground truth surface normals, including mean, median, and percentage of predictions within specific angular thresholds (11.25°, 22.5°, 30°).
Attributes:
-
metric_names–List of metric names ["mean", "median", "<11.25", "<22.5", "<30"].
-
record–List storing angular errors (in degrees) for all pixels across batches.
Source code in fusion_bench/metrics/nyuv2/normal.py
__init__()
¶
Initialize the NormalMetric with state for recording angular errors.
compute()
¶
Compute final metric values from all recorded angular errors.
Returns:
-
–
List[Tensor]: A list containing five metrics: - mean: Mean angular error in degrees. - median: Median angular error in degrees. - <11.25: Percentage of pixels with error < 11.25°. - <22.5: Percentage of pixels with error < 22.5°. - <30: Percentage of pixels with error < 30°.
Note
Returns zeros if no data has been recorded.
Source code in fusion_bench/metrics/nyuv2/normal.py
update(preds, target)
¶
Update metric state with predictions and targets from a batch.
Parameters:
-
preds–Predicted surface normals of shape (batch_size, 3, height, width). Will be L2-normalized before computing errors.
-
target–Ground truth surface normals of shape (batch_size, 3, height, width). Already normalized on NYUv2 dataset. Pixels with sum of 0 are invalid.
Source code in fusion_bench/metrics/nyuv2/normal.py
NoiseMetric
¶
Bases: Metric
A placeholder metric for noise evaluation on NYUv2 dataset.
This metric currently serves as a placeholder and always returns a value of 1. It can be extended in the future to include actual noise-related metrics.
Note
This is a dummy implementation that doesn't perform actual noise measurements.
Source code in fusion_bench/metrics/nyuv2/noise.py
Continual Learning Metrics¶
fusion_bench.metrics.continual_learning
¶
compute_backward_transfer(acc_Ti, acc_ii)
¶
Compute the backward transfer (BWT) of a model on a set of tasks.
Equation
\(BWT = \frac{1}{n} \sum_{k=1}^{n} (acc_{T,i}[k] - acc_{i,i}[k])\)
Returns:
-
float(float) –The backward transfer of the model.