Giter Site home page Giter Site logo

alexellis / tensorflow-serving-openfaas Goto Github PK

View Code? Open in Web Editor NEW
46.0 4.0 6.0 5 KB

Example of using TensorFlow Serving with OpenFaaS

License: MIT License

Dockerfile 100.00%
tensorflow machine-learning ai tf tensorflow-serving docker openfaas serverless function

tensorflow-serving-openfaas's Introduction

tensorflow-serving-openfaas

Example of packaging TensorFlow Serving with OpenFaaS to be deployed and managed through OpenFaaS with auto-scaling, scale-from-zero and a sane configuration for Kubernetes.

This example was adapted from: https://www.tensorflow.org/serving

Pre-reqs

Instructions

  • Clone the repo
$ mkdir -p ~/dev/
$ cd ~/dev/
$ git clone https://github.com/alexellis/tensorflow-serving-openfaas
  • Clone the sample model and copy it to the function's build context
$ cd ~/dev/tensorflow-serving-openfaas

$ git clone https://github.com/tensorflow/serving

$ cp -r serving/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu ./ts-serve/saved_model_half_plus_two_cpu
  • Edit the Docker Hub username

You need to edit the stack.yml file and replace alexellis2 with your Docker Hub account.

  • Build the function image
$  faas-cli build

You should now have a Docker image in your local library which you can deploy to a cluster with faas-cli up

  • Test the function locally

All OpenFaaS images can be run stand-alone without OpenFaaS installed, let's do a quick test, but replace alexellis2 with your own name.

$ docker run -p 8081:8080 -ti alexellis2/ts-serve:latest

Now in another terminal:

$ curl -d '{"instances": [1.0, 2.0, 5.0]}' \
   -X POST http://127.0.0.1:8081/v1/models/half_plus_two:predict

{
    "predictions": [2.5, 3.0, 4.5
    ]
}

From here you can run faas-cli up and then invoke your function from the OpenFaaS UI, CLI or REST API.

$ export OPENFAAS_URL=http://127.0.0.1:8080

$ curl -d '{"instances": [1.0, 2.0, 5.0]}' $OPENFAAS_URL/function/ts-serve/v1/models/half_plus_two:predict

{
    "predictions": [2.5, 3.0, 4.5
    ]
}

Find out more information about your function's endpoints:

$ faas-cli describe ts-serve
Name:                ts-serve
Status:              Ready
Replicas:            1
Available replicas:  1
Invocations:         5
Image:               alexellis2/ts-serve:latest
Function process:    
URL:                 http://127.0.0.1:8080/function/ts-serve
Async URL:           http://127.0.0.1:8080/async-function/ts-serve
Labels:              com.openfaas.function : ts-serve
                     function : true
  • Try your own model

Now you can try your own model by editing ts-serve/Dockerfile.

Let me know what you think via Twitter

tensorflow-serving-openfaas's People

Contributors

alexellis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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