Copyright 2021 (c) Pierre-Emmanuel Novac penovac@unice.fr Université Côte d'Azur, CNRS, LEAT. All rights reserved.
Qualia-CodeGen-Core
Converts a pre-trained Keras .h5 or PyTorch model to C code for inference.
Generated C code uses channels_last data format.
Supported layers
- Activation: ReLU (combined to previous Conv1D, Dense, MaxPooling1D, AveragePooling1D AddV2), Softmax
- Conv1D: optional bias, valid padding only
- Dense: optional bias
- MaxPooling1D: valid padding only
- AveragePooling1D: valid padding only
- Flatten: implies reordering next layer's kernel for data format conversion
- ZeroPadding1D: combined with next Conv1D
- AddV2
Dependencies
python >= 3.9
Python:
jinja2
numpy
Keras
Python:
tensorflow >= 2.6.0
keras >= 2.6.0
PyTorch
Python:
torch >= 1.8.0
Installation
pip install -e .
Usage
Generate C code from Keras .h5
qualia_codegen <model.h5> <output directory>
Use in your C code
Include the model: (can also be built as a separate object)
#include "model.h"
Allocate inputs and outputs arrays with correct dimensions. Remember that inputs must have channels_last data format.
Call it in your C code:
cnn(inputs, outputs);
Add the source file model.c to your build system. It includes all the other source files for layers, don't add these to the build system.
Examples
See the src/qualia_codegen_core/examples/Linux directory for a demo console application to evaluate model accuracy.
src/qualia_codegen_core/examples/qualia_codegen-NucleoL476RG contains an STM32CubeIDE project for the Nucleo-L476RG board that's currently broken due to some recent changes
Documentation
Nothing much…
Source tree
src/qualia_codegen_core/Allocator.py: manages activation buffer allocation. Tries to group all buffers into one, except when they cannot be overwritten (dependencies).
src/qualia_codegen_core/Converter.py: the actual conversion code, parses a Keras model and use the template file associated to each layer to generate C code. When weights have to be written, they are optionally quantized to fixed-point by setting the appropriate parameters of Converter constructor (see its definition)
src/qualia_codegen_core/Validator.py: work in progress, should contain functions to check if a model can be successfully converted. For now only check activation function.
src/qualia_codegen_core/assets/: contains the templates to generate C inference code
src/qualia_codegen_core/assets/layers/: contains the implementation of the various supported layers
src/qualia_codegen_core/assets/layers/weights: contains the support for the trainable layers weights
Metadata
Release files for qualia-codegen-core 2.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qualia_codegen_core-2.6.0.tar.gz | 7.5 MB | Without provenance | Details for qualia_codegen_core-2.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qualia_codegen_core-2.6.0-py3-none-any.whl | Python 3 | none | any | Details for qualia_codegen_core-2.6.0-py3-none-any.whl |
Total release size: 15.8 MB
Release files / qualia_codegen_core-2.6.0.tar.gz
| Download URL | qualia_codegen_core-2.6.0.tar.gz |
|---|---|
| Size | 7.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ae8dedef5008ed392f0f52ff9e9a99eabbad4e876fae8c857c4bd713e2f73dac
|
|
BLAKE2b-256 checksum How to use checksums |
397acfb8c32ee68144ae9fa454ac4f30367cb1b24cd230ab3cb19f241a69431b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.26.7 CPython/3.14.4 Linux/6.18.26-2-lts
|
Release files / qualia_codegen_core-2.6.0-py3-none-any.whl
| Download URL | qualia_codegen_core-2.6.0-py3-none-any.whl |
|---|---|
| Size | 8.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab44b82e37044f8faf5f1b8e2ff0c3d8db7f7c937cb009b205770b0d94fceb06
|
|
BLAKE2b-256 checksum How to use checksums |
7897beb3b2e35077c9534f463794dfd0de51ae448eceb21d746bb138fcffa194
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.26.7 CPython/3.14.4 Linux/6.18.26-2-lts
|
Security for qualia-codegen-core 2.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.