Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
K

keras2cpp

> 编程语言
Open source

This is a bunch of code to port Keras neural network model into pure C++.

681 stars0 likes2 views
WebsiteGitHub

About

This is a bunch of code to port Keras neural network model into pure C++.

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 > > 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

  1. Save your network weights and architecture.
  2. Dump network structure to plain text file with dump_to_simple_cpp.py script.
  3. Use network with code from keras_model.h and keras_model.cc files - see example below.

Example

  1. Run one iteration of simple CNN on MNIST data with example/mnist_cnn_one_iteration.py script. It will produce files with architecture example/my_nn_arch.json and weights in HDF5 format example/my_nn_weights.h5.
  2. 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.
  3. Compile example g++ -std=c++11 keras_model.cc example_main.cc - see code in example_main.cc.
  4. 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:

  1. Dump network into text file.
  2. Generate random sample.
  3. Compute predictions from keras and keras2cpp on generated sample.
  4. Compare predictions.

Similar repositories

  • Keras to C++ with usage of Tensorflow C API https://github.com/aljabr0/from-keras-to-c

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++kerasmachine-learningneural-network

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言