rslearn.train.metrics¶
metrics ¶
Metric output classes for non-scalar metrics.
NonScalarMetricOutput
dataclass
¶
Bases: ABC
Base class for non-scalar metric outputs that need special logging.
Subclasses should implement the log_to_wandb method to define how the metric should be logged (only supports logging to Weights & Biases).
Source code in rslearn/train/metrics.py
log_to_wandb
abstractmethod
¶
ConfusionMatrixOutput
dataclass
¶
Bases: NonScalarMetricOutput
Confusion matrix metric output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confusion_matrix
|
Tensor
|
confusion matrix of shape (num_classes, num_classes) where cm[i, j] is the count of samples with true label i and predicted label j. |
required |
class_names
|
list[str] | None
|
optional list of class names for axis labels |
None
|
Source code in rslearn/train/metrics.py
log_to_wandb ¶
Log confusion matrix to wandb.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the metric name (e.g., "val_confusion_matrix") |
required |
Source code in rslearn/train/metrics.py
ConfusionMatrixMetric ¶
Bases: Metric
Confusion matrix metric that works on flattened inputs.
Expects preds of shape (N, C) and labels of shape (N,). Should be wrapped by ClassificationMetric or SegmentationMetric which handle the task-specific preprocessing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_classes
|
int
|
number of classes |
required |
class_names
|
list[str] | None
|
optional list of class names for labeling |
None
|
Source code in rslearn/train/metrics.py
update ¶
Update metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preds
|
Tensor
|
predictions of shape (N, C) - probabilities |
required |
labels
|
Tensor
|
ground truth of shape (N,) - class indices |
required |
Source code in rslearn/train/metrics.py
compute ¶
compute() -> ConfusionMatrixOutput
Returns the confusion matrix wrapped in ConfusionMatrixOutput.