Skip to content

UBICO/model-splitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Model Split

🇮🇹 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).

Setup

python3.11 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Usage

  1. Put your model in models/ (e.g. models/FOMO_224.h5).
  2. Run the split, passing the file name with its extension:
python model_split.py FOMO_224.h5

Output

One 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

How it works

The script (model_split.py):

  1. Loads the .h5 from models/.
  2. Iterates over the model's layers; for each one it builds a mini-model Input -> layer.
  3. Saves each submodel as .h5, converts it to .tflite and generates its .h header.
  4. layers.h gathers all headers and emits the LOAD_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=1 and uses the tf-keras package to stay compatible (Keras 3 removed layer.input_shape and the groups argument of DepthwiseConv2D).

Research Publications

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.

Main Contributions

  • Lorenzo Lamazzi
  • Jun Wu Wang
  • Francesco Franco
  • Luca Bedogni

About

Splits a Keras `.h5` model into per-layer submodels

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages