The purpose of this project is to utilize Python's Keras models from Rust for inference. It aims to achieve significantly faster and more efficient processing compared to traditional methods.
- Train and setup model using Python\Keras.
- Save your model as .keras file
- Use result model arhitecture and weights from Rust.
Currently, the project has been tested only with CPU execution. As an example, we train the model using the MNIST dataset. With the provided example, we've observed a remarkable 10x increase in execution speed!
Supported layers:
Input | Flatten | Dense | Conv2D | MaxPooling2D | Dropout | LSTM |
---|---|---|---|---|---|---|
✓ | ✓ | ✓ |
To build the script, you need to install the HDF5 module.
NOTE: Currently, the Rust HDF5 module only supports versions 8, 10, and 12. I tested with version 12.
Add the HDF5_DIR
to the installed directory so that the module knows where to find the binaries. All other modules can be obtained fully through Cargo.
To run the example and obtain the model, follow these steps:
-
Run keras_example.ipynb.
- If you're not familiar with Python, follow these instructions:
- Install TensorFlow.
- Run the following command:
pip install jupyterlab tensorflow_datasets
- Open Jupyter Notebook from the current folder:
cd /path/to/current/dir jupyter lab
- Run the following command to execute all cells and obtain the result.
- Alternatively, interact with the notebook as desired.
- If you're not familiar with Python, follow these instructions:
-
After running the notebook, you will have a
model.keras
file, which is a zip archive.- Note: The crate currently does NOT support zip extraction, so please extract the files manually to the same folder. You will obtain the required files for this example:
model.weights.h5
: Contains all the weights.config.json
: Contains module configuration.test_data.npz
: Archive with test examples used for testing.
- Note: The crate currently does NOT support zip extraction, so please extract the files manually to the same folder. You will obtain the required files for this example:
-
At the current stage, only the
Sequential
model is supported. -
Run the module:
cargo run
License This project is licensed under the MIT License.
Acknowledgements Special thanks to the contributors and supporters of the project for their valuable input and feedback.