Skip to main content

10.1 Model Preparation

This phase covers building the example 1D-CNN model, exporting it to int8 TFLite format, generating quantized input data, and producing the C byte arrays embedded in the MCU firmware. The source files for this phase (model_keras.py, export_tflite.py, gen_input_data.py) are provided alongside this document. Install dependencies on Host Machine once before running any script:

10.1.1 Reference Model Architecture

The example model is a minimal 1D-CNN with random weights.

10.1.1.1 Model Graph

BatchNormalization is folded into the Conv2D weights during export — it does not appear as a separate op in the quantized graph. The int8 model has exactly 3 operators.

10.1.2 Source Files

10.1.2.1 model_keras.py — Model Definition

Defines the Keras model architecture.

10.1.2.2 export_tflite.py — Export Float32 and Int8 TFLite

Builds the model from model_keras.py, runs full-integer quantization with a random representative dataset, and validates both outputs.
Run:
Outputs: The script also prints the input quantization parameters (scale, zero_point) used internally by gen_input_data.py.

10.1.2.3 gen_input_data.py — Generate Quantized Input Files

Reads quantization parameters directly from the exported int8 model, then generates 200-sample int8 windows from a real dataset or synthetic data.
Run:
Outputs (in inputs/ folder):

10.1.3 Verify on Host

Before integrating model with MCU Firmware, confirm the model runs correctly with the generated input:
Expected shape and type (values depend on random weights):