profiler
birdnet_stm32.models.profiler
¶
Model profiling: per-layer MACs, parameters, and activation memory.
Provides a simple profiling utility that inspects a Keras model and reports per-layer statistics useful for estimating NPU/MCU cost.
LayerProfile
dataclass
¶
Per-layer profiling result.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Layer name. |
layer_type |
str
|
Keras layer class name. |
output_shape |
str
|
Output shape as string. |
params |
int
|
Number of trainable + non-trainable parameters. |
macs |
int
|
Estimated multiply-accumulate operations. |
activation_bytes |
int
|
Estimated activation memory in bytes (float32). |
n6_supported |
bool
|
Whether this layer type is known to be N6 NPU-compatible. |
Source code in birdnet_stm32/models/profiler.py
profile_model(model)
¶
Profile a Keras model and return per-layer statistics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Compiled or uncompiled Keras model. |
required |
Returns:
| Type | Description |
|---|---|
list[LayerProfile]
|
List of LayerProfile for each layer. |
Source code in birdnet_stm32/models/profiler.py
print_profile(model, warn_unsupported=True)
¶
Print a formatted profiling table for a Keras model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Keras model to profile. |
required |
warn_unsupported
|
bool
|
Print warnings for layers not known to be N6-compatible. |
True
|
Source code in birdnet_stm32/models/profiler.py
check_n6_compatibility(model)
¶
Check model for layers with unknown N6 NPU compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
Keras model to check. |
required |
Returns:
| Type | Description |
|---|---|
list[LayerProfile]
|
List of LayerProfile for layers not known to be N6-compatible |
list[LayerProfile]
|
(excludes InputLayer). |