🇮🇹 Versione italiana: README.it.md
Splits a Keras .h5 model into per-layer submodels, exporting each one in three formats: .h5 (Keras), .tflite (TensorFlow Lite) and .h (C array for microcontrollers).
python3.11 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt- Put your model in
models/(e.g.models/FOMO_224.h5). - Run the split, passing the file name with its extension:
python model_split.py FOMO_224.h5One submodel is created per layer (the InputLayer is skipped), saved under:
models/<model-name>/layers/
├── h5/ submodel_<i>.h5 Keras submodel
├── tflite/ submodel_<i>.tflite TensorFlow Lite version
└── h/ layer_<i>.h C array of the .tflite
+ layers.h includes every layer and defines the LOAD_LAYER() macro
The script (model_split.py):
- Loads the
.h5frommodels/. - Iterates over the model's layers; for each one it builds a mini-model
Input -> layer. - Saves each submodel as
.h5, converts it to.tfliteand generates its.hheader. layers.hgathers all headers and emits theLOAD_LAYER()macro to select a layer at runtime on the firmware.
Keras note: the models are saved with Keras 2. The script sets
TF_USE_LEGACY_KERAS=1and uses thetf-keraspackage to stay compatible (Keras 3 removedlayer.input_shapeand thegroupsargument ofDepthwiseConv2D).
This work is a part of the following research:
- Lamazzi, L., Wang, J. W., Franco, F., & Bedogni, L. (2026, January). SCIoT: Design and Evaluation of a Split Computing Framework for Collaborative Inference in the IoT. In 2026 IEEE 23rd Consumer Communications & Networking Conference (CCNC) (pp. 1-6). IEEE.
- Lorenzo Lamazzi
- Jun Wu Wang
- Francesco Franco
- Luca Bedogni