Code Monkey home page Code Monkey logo

ofxkerasify's Introduction

ofxKerasify

openFrameworks addon for Running trained Keras Deep Learning models in C++.

based on moof2k's wonderful kerasify project. https://github.com/moof2k/kerasify

Disclaimer

Example 1: MNIST MLP (example-mnist_mlp)

  1. Train MLP model for MNIST using Keras example https://github.com/fchollet/keras/blob/master/examples/mnist_mlp.py

  2. Save trained model model.save('mnist_mlp.h5')

  3. "Kerasify" the saved model using python script

$ python convert_keras_model.py mnist_mlp.h5 mnist_mlp.model
  1. Copy the converted model into "data" folder of ofApp

  2. Load model

kerasify.loadModel("mnist_mlp.model");
  1. Inference
// Image -> vector
ofPixels pix = img.getPixels();
std::vector<float> input;
for (int i = 0; i < pix.size(); i++){
    input.push_back(pix.getData()[i]/255.0);
}

// INFERENCE
output.resize(10); // output vector should be [10]. because we have 10 digits! ;-)
kerasify.predict(input, output);
  1. Voila!

screenshot

Example 2: Image Regression for iOS (example-ios-imageregression)

This sample project is for oF iOS

"Image Regression" - "treats the pixels of an image as a learning problem: it takes the (x,y) position on a grid and learns to predict the color at that point using regression to (r,g,b). It's a bit like compression, since the image information is encoded in the weights of the network, but almost certainly not of practical kind :)"" by @karpathy.

Here is his great online demo.

I trained a simple fully-connected 8-layer network for this image of dog. https://github.com/naotokui/ChainerPainter/blob/master/ChainerPainter.ipynb
screenshot

You can run the trained model on iOS now!
(Don't forget to use convert_keras_model.py)

screenshot

Let's see what happens when you randomly disable one of trained layers.

screenshot

ofxkerasify's People

Contributors

naotokui avatar

Watchers

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