birdnet_tiny_forge.targets package

Submodules

birdnet_tiny_forge.targets.base module

Abstract base class for all targets. It provides a base implementation for the rendering of a project template given a context dict (that is populated by the inheriting child class).

class birdnet_tiny_forge.targets.base.BuildTargetBase(feature_extractor: FeatureExtractorBase, model: keras.Model, reference_dataset: tensorflow.data.Dataset, labels_dict: dict, params: dict)

Bases: ABC

check_feature_extractor_compatible() bool

Check feature extractor compatibility with target.

Raises:

ValueError if extractor is not compatible with target.

classmethod check_labels(labels_dict: dict)
check_model_compatible()

Check model compatibility with target.

Raises:

ValueError if model is not compatible with target.

abstract do_check_feature_extractor_compatible()
Raises:

ValueError if extractor is not compatible with target.

abstract do_check_model_compatible()
Raises:

ValueError if model is not compatible with target.

abstract extract_context() dict
classmethod get_templates_dir()

Return templates dir for this build target. Inheriting classes can override this if needed.

abstract classmethod get_toolchain() type[ToolchainBase]
process_target_templates(outdir: Path) None
classmethod setup_template_environment(template_dir)
validate()

Validate Target inputs, including the compatibility of feature extractor and model.

birdnet_tiny_forge.targets.korvo2_bird_logger module

Build target for korvo2_bird_logger template project. The class will check that the operations from the input keras model are supported by tflite-micro. It then converts the keras model to tflite, and prepares all the information needed by the project template to generate the final code.

class birdnet_tiny_forge.targets.korvo2_bird_logger.Korvo2BirdLogger(feature_extractor: FeatureExtractorBase, model: keras.Model, reference_dataset: tensorflow.data.Dataset, labels_dict: dict, params: dict)

Bases: BuildTargetBase

do_check_feature_extractor_compatible()
Raises:

ValueError if extractor is not compatible with target.

do_check_model_compatible()
Raises:

ValueError if model is not compatible with target.

extract_context() dict
static get_model_buf(model: keras.Model, reference_dataset: tensorflow.data.Dataset)
classmethod get_toolchain()
birdnet_tiny_forge.targets.korvo2_bird_logger.get_model_ops_and_acts(model_buf)

Extracts a set of operators from a tflite model.

This fn is adapted from tensorflow lite micro tools scripts: (https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/tools/gen_micro_mutable_op_resolver/generate_micro_mutable_op_resolver_from_model.py)

birdnet_tiny_forge.targets.korvo2_bird_logger.parse_op_str(op_str)

Converts a flatbuffer operator string to a format suitable for Micro Mutable Op Resolver. Example: CONV_2D –> AddConv2D.

This fn is adapted from tensorflow lite micro tools scripts: (https://github.com/tensorflow/tflite-micro/tree/main/tensorflow/lite/micro/tools/gen_micro_mutable_op_resolver/generate_micro_mutable_op_resolver_from_model.py)

birdnet_tiny_forge.targets.korvo2_bird_logger.tflite_to_byte_array(tflite_file: Path)