Keras2cpp
This is a bunch of code to port Keras neural network model into pure C++.
Install / Use
/learn @pplonski/Keras2cppREADME
keras2cpp
This is a bunch of code to port Keras neural network model into pure C++. Neural network weights and architecture are stored in plain text file and input is presented as vector<vector<vector<float> > > in case of image. The code is prepared to support simple Convolutional network (from MNIST example) but can be easily extended. There are implemented only ReLU and Softmax activations.
It is working with the Theano backend.
Usage
- Save your network weights and architecture.
- Dump network structure to plain text file with
dump_to_simple_cpp.pyscript. - Use network with code from
keras_model.handkeras_model.ccfiles - see example below.
Example
- Run one iteration of simple CNN on MNIST data with
example/mnist_cnn_one_iteration.pyscript. It will produce files with architectureexample/my_nn_arch.jsonand weights in HDF5 formatexample/my_nn_weights.h5. - Dump network to plain text file
python dump_to_simple_cpp.py -a example/my_nn_arch.json -w example/my_nn_weights.h5 -o example/dumped.nnet. - Compile example
g++ -std=c++11 keras_model.cc example_main.cc- see code inexample_main.cc. - Run binary
./a.out- you shoul get the same output as in step one from Keras.
Testing
If you want to test dumping for your network, please use test_run.sh script. Please provide there your network architecture and weights. The script do following job:
- Dump network into text file.
- Generate random sample.
- Compute predictions from keras and keras2cpp on generated sample.
- Compare predictions.
Similar repositories
- Keras to C++ with usage of Tensorflow C API https://github.com/aljabr0/from-keras-to-c
Related Skills
YC-Killer
2.7kA library of enterprise-grade AI agents designed to democratize artificial intelligence and provide free, open-source alternatives to overvalued Y Combinator startups. If you are excited about democratizing AI access & AI agents, please star ⭐️ this repository and use the link in the readme to join our open source AI research team.
API
A learning and reflection platform designed to cultivate clarity, resilience, and antifragile thinking in an uncertain world.
best-practices-researcher
The most comprehensive Claude Code skills registry | Web Search: https://skills-registry-web.vercel.app
groundhog
398Groundhog's primary purpose is to teach people how Cursor and all these other coding agents work under the hood. If you understand how these coding assistants work from first principles, then you can drive these tools harder (or perhaps make your own!).
