metrics
birdnet_stm32.evaluation.metrics
¶
Evaluation metrics and per-file inference pipeline.
make_chunks_for_file(path, cfg, frontend, mag_scale, n_fft, chunk_overlap)
¶
Build a list of model-ready inputs from one audio file by chunking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Audio file path. |
required |
cfg
|
dict
|
Training config dict (sample_rate, chunk_duration, num_mels, spec_width). |
required |
frontend
|
str
|
'librosa'|'hybrid'|'raw'. |
required |
mag_scale
|
str
|
Magnitude scaling for precomputed paths. |
required |
n_fft
|
int
|
FFT length. |
required |
chunk_overlap
|
float
|
Overlap fraction (seconds) between consecutive chunks. |
required |
Returns:
| Type | Description |
|---|---|
list[ndarray]
|
List of per-chunk inputs ready for model.predict. |
Source code in birdnet_stm32/evaluation/metrics.py
evaluate(model_runner, files, classes, cfg, pooling='average', batch_size=64, overlap=0.0, mep_beta=10.0, measure_latency=False, profile_memory=False)
¶
Run inference per chunk, pool to file-level, and compute metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_runner
|
Runner exposing predict(x_batch). |
required | |
files
|
list[str]
|
List of file paths to evaluate. |
required |
classes
|
list[str]
|
Ordered class names. |
required |
cfg
|
dict
|
Training config dict. |
required |
pooling
|
str
|
'avg'|'max'|'lme' pooling method. |
'average'
|
batch_size
|
int
|
Batch size for chunk inference. |
64
|
overlap
|
float
|
Overlap in seconds for chunking. |
0.0
|
mep_beta
|
float
|
Temperature for LME pooling. |
10.0
|
measure_latency
|
bool
|
If True, measure per-chunk inference latency. |
False
|
profile_memory
|
bool
|
If True, report peak RSS during inference. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[dict, list[dict], ndarray, ndarray]
|
Tuple of (metrics dict, per_file list, y_true array, y_scores array). |
Source code in birdnet_stm32/evaluation/metrics.py
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
optimize_thresholds(y_true, y_scores, classes)
¶
Find per-class thresholds that maximize F1 using the precision-recall curve.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ndarray
|
Binary ground-truth array of shape |
required |
y_scores
|
ndarray
|
Predicted scores of shape |
required |
classes
|
list[str]
|
Class name list matching the column order. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary mapping each class name to its optimal threshold. |
Source code in birdnet_stm32/evaluation/metrics.py
bootstrap_ap_ci(y_true, y_scores, classes, n_bootstrap=1000, confidence=0.95, seed=42)
¶
Compute per-class AP with bootstrap confidence intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ndarray
|
Binary ground-truth array |
required |
y_scores
|
ndarray
|
Predicted scores |
required |
classes
|
list[str]
|
Class name list matching column order. |
required |
n_bootstrap
|
int
|
Number of bootstrap resamples. |
1000
|
confidence
|
float
|
Confidence level (e.g. 0.95 for 95% CI). |
0.95
|
seed
|
int
|
Random seed for reproducibility. |
42
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
List of dicts, one per class: |
list[dict]
|
|
Source code in birdnet_stm32/evaluation/metrics.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
compute_det_curve(y_true, y_scores)
¶
Compute Detection Error Tradeoff (DET) curve points.
The DET curve plots false rejection rate (FRR = 1 - recall) against false acceptance rate (FAR = FPR) across thresholds. Standard in bioacoustics evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_true
|
ndarray
|
Binary ground-truth (flattened or 2-D, treated as binary). |
required |
y_scores
|
ndarray
|
Predicted scores (same shape as y_true). |
required |
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray, ndarray]
|
Tuple (far, frr, thresholds) — arrays of equal length. |