rslearn.train.metrics¶
metrics ¶
Metric output classes for non-scalar metrics.
NonScalarMetricOutput
dataclass
¶
Base class for non-scalar metric outputs that need special logging.
Subclasses should implement the platform-specific methods for the loggers they support. Unsupported loggers are skipped with a warning.
Source code in rslearn/train/metrics.py
log_to_wandb ¶
Log this metric to wandb.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the metric name |
required |
log_to_mlflow ¶
Log this metric to MLflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the metric name. |
required |
client
|
Any
|
the MLflow client associated with the Lightning logger. |
required |
run_id
|
str
|
the MLflow run ID. |
required |
Source code in rslearn/train/metrics.py
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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
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
log_to_mlflow ¶
Log the confusion matrix as MLflow table and figure artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the metric name (e.g., |
required |
client
|
Any
|
the MLflow client associated with the Lightning logger. |
required |
run_id
|
str
|
the MLflow run ID. |
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.