Konverter Konverter Tests

Convert your Keras models into pure Python ๐Ÿ+ NumPy.

The goal of this tool is to provide a quick and easy way to execute Keras models on machines or setups where utilizing TensorFlow/Keras is impossible. Specifically, in my case, to replace SNPE (Snapdragon Neural Processing Engine) for inference on phones with Python.

Supported Keras Model Attributes

Roadmap ๐Ÿ›ฃ

The project to do list can be found here.

Features ๐Ÿค–

Benchmarks ๐Ÿ“ˆ

Benchmarks can be found in BENCHMARKS.md.

Installation & Usage ๐ŸŒ

Install Konverter using pip:

pip install keras-konverter

Konverting using the CLI: ๐Ÿ–ฅ

konverter examples/test_model.h5 examples/test_model.py (py suffix is optional)

Type konverter to get all possible arguments and flags!

Konverting programmatically: ๐Ÿค–

All parameters with defaults: konverter.konvert(input_model, output_file=None, indent=2, silent=False, no_watermark=False, tf_verbose=False)

>>> import konverter
>>> konverter.konvert('examples/test_model.h5', output_file='examples/test_model')

Note: The model file will be saved as f'{output_file}.py' and the weights will be saved as f'{output_file}_weights.npz' in the same directory. Make sure to change the path inside the model wrapper if you move the files after Konversion.


Thatโ€™s it! If your model is supported (check Supported Keras Model Attributes), then your newly converted Konverter model should be ready to go.

To predict: Import your model wrapper and run the predict() function. โ—Always double check that the outputs closely match your Keras modelโ€™sโ— Automatic verification will come soon. For the integrity of the predictions, always make sure your input is a np.float32 array.

import numpy as np
from examples.test_model import predict
predict([np.random.rand(3).astype(np.float32)])

See limitations and issues.

Demo

Dependencies

Thanks to @apiad you can now use Poetry to install all the needed dependencies for this tool! However the requirements are a pretty short list:

To install all needed dependencies, simply cd into the base directory of Konverter, and run:

poetry install --no-dev

If you would like to use this version of Konverter (not from pip), then you may need to also run poetry shell after to enter poetryโ€™s virtualenv environment. If you go down this path, make sure to remove --no-dev so TensorFlow installs in the venv!

Current Limitations and Issues ๐Ÿ˜ฌ