Giter Club home page Giter Club logo

keras2cpp's Introduction

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 - support for Tensorflow will be added soon.

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

keras2cpp's People

Contributors

pplonski avatar robertsulej avatar ckirksey3 avatar blackarrow3542 avatar ypwhs avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.