Skip to main content

ML model to low-level inference convertor

Project description

model2c

pypi build PyPI version

About the Project

Python API and Command Line tool to convert ML models into low-level inference for embedded platforms

Getting Started

Prerequisites

Make sure you have tensorflow tf2onnx or torch installed.

Furthermore, make sure you have onnx2c installed and added to PATH.

Lastly you need ProtocolBuffers libraries installed, e.g.:

  • Ubuntu: apt install libprotobuf-dev protobuf-compiler
  • MacOS: brew install protobuf

Get the sources:

git clone https://github.com/kraiskil/onnx2c.git
cd onnx2c
git submodule update --init

Then run a standard CMake build

mkdir build
cd build
cmake ..
make onnx2c

And finally add to path

export PATH=$PATH:/path/to/onnx2c/folder

Installation

You can can install the package through pypi:

pip install model2c

Or you can clone the repo and build directly from source:

git clone git@github.com:h3x4g0ns/model2c.git
cd model2c
make install

Usage

Train a model with correponding data until sufficient metrics are obtained.

import torch
import model2c.pytorch import convert

# run convertor
convert(model=torch_model, 
        input_shape=(batch_size, 1, 224, 224),
        quantization="fp32",
        output_file="model.c")
print(f"size of output model: {os.path.getsize('model.c')/1024} kilobytes")

Support

model2c currently supports the following ML frameworks

  • torch
  • tf/keras

To Do

  • torch convert
  • tf convert
  • make command line utility
  • include dynamic axis for batch size

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

model2c-1.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

model2c-1.1.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file model2c-1.1.1.tar.gz.

File metadata

  • Download URL: model2c-1.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for model2c-1.1.1.tar.gz
Algorithm Hash digest
SHA256 9377e7313ab14fcc73675d5ce5a32cc092ad14984f60e1b6b71e2de2a180762e
MD5 ec4b1737c2cda3d79a64b871df035665
BLAKE2b-256 88e37bb80e0c6a76cb60525b7fdd56f39e08644cc88cb87431bac7eda27d9442

See more details on using hashes here.

File details

Details for the file model2c-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: model2c-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for model2c-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e013648c9a457be84984ad021f450815c5cda9ca610b272ea20be6827683a974
MD5 bb3f36531ab6caa0ce5bc7df36a4fd19
BLAKE2b-256 f1ab614aaee67e156ab0650a7562f50dfee6002c2f34c701711fe3a4f76223f4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page