Code Monkey home page Code Monkey logo

fn-predict's Introduction

this project packs machine learning models in docker containers to be exposed as fn functions (see serverless project fn) to predict the digit on a 400x400 base64-encoded digit image.

The models are trained using GNU Octave (5000 20x20 gray digit image examples on a Neural Network with 1 hidden layer with 25 units) and Tensorflow (MNIST 28x28 gray digit image examples on a Neural Network with 1 hidden layer with 512 units).

The containers expect a 400x400 base64 encoded digit image on stdin and output the predicted digit and the corresponding probabilities for the digits 1-9 and 0.

The folders octave-docker and tf-docker contain the Dockerfile for building the corresponding containers.

To test octave-docker:

cd octave-docker docker build -t octave-docker . cat ../vier-base64-encoded.txt |docker run -i octave-docker

result: 4 0.00519 0.00069 0.02413 0.96044 0.01314 0.00080 0.00100 0.00118 0.06225 0.00000

To test tf-docker:

cd tf-docker docker build -t tf-docker . cat ../vier-base64-encoded.txt |docker run -i tf-docker

result: 4 0.06309 0.07452 0.04057 0.34499 0.13020 0.05446 0.08988 0.08099 0.09358 0.02772

The folders octave-hotwrap and tf-hotwrap show how above containers can be exposed as Fn functions using Fn hotwrap(https://github.com/fnproject/hotwrap)

To test octave-hotwrap:

cd octave-hotwrap fn -v deploy --no-bump --app predict --local curl -d cat ../vier-base64-encoded.txt http://localhost:8080/t/predict/octave-hotwrap

result: 4 0.00519 0.00069 0.02413 0.96044 0.01314 0.00080 0.00100 0.00118 0.06225 0.00000

To test tf-hotwrap:

cd tf-hotwrap fn -v deploy --no-bump --app predict --local curl -d cat ../vier-base64-encoded.txt http://localhost:8080/t/predict/tf-hotwrap

result: 4 0.06309 0.07452 0.04057 0.34499 0.13020 0.05446 0.08988 0.08099 0.09358 0.02772

The folder tf-python-fdk shows how the tensorflow code used in the tf docker container can be rewritten to use the Fn Python FDK. With this implementation, hot functions are very fast since they execute only the function call back and the time to start the function container and to execute the python initialization code is saved.

To test tf-python-fdk: cd tf-python-fdk fn -v deploy --no-bump --app predict --local time curl -d cat ../vier-base64-encoded.txt http://localhost:8080/t/predict/tf-python-fdk

result (cold function call, if called first time): 4 0.06309 0.07452 0.04057 0.34499 0.13020 0.05446 0.08988 0.08099 0.09358 0.02772 real 0m18.829s user 0m0.005s sys 0m0.012s

result (hot function call, if called within 30s from last one): 4 0.06309 0.07452 0.04057 0.34499 0.13020 0.05446 0.08988 0.08099 0.09358 0.02772 real 0m0.190s user 0m0.003s sys 0m0.010s

fn-predict's People

Contributors

doschkinow avatar

Stargazers

Werner Keil avatar

Watchers

James Cloos 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.