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', 'mfcc', 'log_mel'). |
mag_scale |
str
|
Magnitude scaling ('pwl', 'pcen', 'db', 'none'). |
embeddings_size |
int
|
Dense embedding dimension before classifier. |
alpha |
float
|
Width multiplier for channel counts. |
depth_multiplier |
int
|
Block repeat count per stage. |
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. |
n_mfcc |
int
|
Number of MFCC coefficients (mfcc frontend only). |
use_se |
bool
|
Whether SE channel attention is enabled. |
se_reduction |
int
|
SE reduction factor. |
use_inverted_residual |
bool
|
Whether inverted residual blocks are used. |
expansion_factor |
int
|
Inverted residual expansion factor. |
use_attention_pooling |
bool
|
Whether attention pooling replaces GAP. |
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 | |
__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. |