config
birdnet_stm32.training.config
¶
Model configuration dataclass with JSON serialization and validation.
Replaces the raw dict config previously saved alongside checkpoints. Backward-compatible: loads legacy JSON files that lack newer fields.
ModelConfig
dataclass
¶
Immutable model configuration for training, conversion, and deployment.
Attributes:
| Name | Type | Description |
|---|---|---|
sample_rate |
int
|
Audio sample rate in Hz. |
num_mels |
int
|
Number of mel frequency bins. |
spec_width |
int
|
Spectrogram width in frames. |
fft_length |
int
|
FFT window size. |
chunk_duration |
float
|
Audio chunk duration in seconds. |
hop_length |
int
|
STFT hop length in samples. |
audio_frontend |
str
|
Frontend mode ('librosa', 'hybrid', 'raw'). |
mag_scale |
str
|
Magnitude scaling ('pwl', 'none'). |
input_compression |
str
|
Compression of a precomputed spectrogram input before quantization ('none', 'sqrt', 'log'); librosa/hybrid only. |
raw_magnitude |
str
|
How the raw frontend combines its quadrature pair into a band envelope ('alpha_max', 'l1', 'halfwave'); raw only. The options differ in how many INT8 activation grids sit between the filterbank and the band stage. |
raw_overlap |
int
|
Analysis window of the raw filterbank as a multiple of its hop; raw only. 2 is the release geometry (448 taps at 2.5 s / 256 frames); 1 halves the window, its MACs and the number of partial convolutions it is emitted as. |
raw_bank |
str
|
How the raw quadrature pair is emitted: 'pair' (two banks, as every model up to 1.4) or 'fused' (one bank of 2*num_mels filters, sliced into the two components). Identical arithmetic, half the convolutions and summations; raw only. |
raw_exposure_gain |
float
|
Gain of the raw filterbank's second, clamped exposure; 1 means one exposure (every release). Experimental; raw only. |
raw_exposure_mode |
str
|
'channels' (both exposures to the backbone) or 'compress' (mixed per band into a knee compressor). Experimental. |
output_activation |
str
|
What the converted model emits: 'sigmoid' probabilities (default) or raw 'logit' scores. A logit model leaves the sigmoid to the caller, which keeps the output off the INT8 1/256 probability grid; see docs/inference.md. |
embeddings_size |
int
|
Dense embedding dimension before classifier. |
alpha |
float
|
Width multiplier for channel counts. |
depth_multiplier |
int
|
Block repeat count per stage. |
head_pooling |
str
|
Pooling head; 'gap' is the only one. |
dw_kernel_size |
int
|
Depthwise kernel size in stages 2-4 (3 or 5). |
stage_widths |
list[int]
|
Base output channels of the four stages, before alpha. The
default is what configs saved before the field existed were built
with; |
backbone |
str
|
'dscnn' (releases up to 2.1; configs saved before the field
existed), 'efficientnet_b0_n6' (N6-B0, 2.2) or 'efficientnet_b0_n6w'
(that with wider bottlenecks, 2.3); alpha, depth_multiplier,
dw_kernel_size and stage_widths do not apply to the EfficientNet
ones. |
num_classes |
int
|
Number of output classes. |
class_names |
list[str]
|
Ordered list of class label strings. |
frontend_trainable |
bool
|
Whether frontend weights are trainable. |
dropout_rate |
float
|
Dropout rate before classifier head. |
Source code in birdnet_stm32/training/config.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
__post_init__()
¶
Validate field values after initialization.
Source code in birdnet_stm32/training/config.py
to_dict()
¶
save(path)
¶
Write config to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Destination file path. |
required |
Source code in birdnet_stm32/training/config.py
from_dict(data)
classmethod
¶
Create a ModelConfig from a dict, ignoring unknown keys.
Unknown keys are silently dropped so legacy configs still load.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
Dictionary of config values. |
required |
Returns:
| Type | Description |
|---|---|
ModelConfig
|
Validated ModelConfig instance. |
Source code in birdnet_stm32/training/config.py
load(path)
classmethod
¶
Load config from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to JSON config file. |
required |
Returns:
| Type | Description |
|---|---|
ModelConfig
|
Validated ModelConfig instance. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If path does not exist. |