Coder Social home page Coder Social logo

juanpabloprado / tensorboot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grolex18/tensorboot

0.0 2.0 0.0 285 KB

Demo application that deploys TensorFlow models as a SpringBoot microservice.

License: Apache License 2.0

Dockerfile 1.04% Shell 5.32% Java 83.26% HTML 6.91% JavaScript 3.47%

tensorboot's Introduction

TensorBoot project

Demo application that deploys TensorFlow models as a SpringBoot microservice. Exposes REST services (with Swagger html docs) and simple web page for image recognition using MobilenetV2 pretrained model.

Contains examples of image file upload using form and how to use browser webcam and call REST service using javascript.

Prerequisites

To build the project, you need to have these installed: JDK 8+ - download it from here.

Download model

Required before builds/deployment

$ ./downlod_model.sh

Model will be stored under model folder.

Also you can use downloadModel maven profile to download model during build:

$ ./mvnw clean install -PdownloadModel

Build project

To build the project, run:

$ ./mvnw clean install

Running the application locally

$ ./run.sh

Possible parameters for script are:

Usage: ./run.sh [-c -d]
   -c Recompile project
   -d Enable debug

Services endpoints

Main application page: http://localhost:8080/

UI file upload page: http://localhost:8080/uploadForm

Rest services are deployed under http://localhost:8080/TensorApi context

Swagger

All REST services have their definitions exposed using Swagger. Once the demo is running locally you can access Swagger using these URLS:

Logging

Application is configured to log to console and into file. You can find daily rolling log files under "log" folder.

Application configuration file

Application is configured in application.yml:

services:
  baseApiPath: /TensorApi                                            # Application services context path

spring:
  servlet:
    multipart:
      enabled: true
      resolve-lazily: true
      max-file-size: 1512KB                                          # Upload file size limit
      max-request-size: 1512KB                                       # Upload request size limit

tensorboot:
  model:
    path: model/mobilenet_v2_1.4_224_frozen.pb                       # Path to model file
    inputSize: 224                                                   # The input size. A square image of inputSize x inputSize is assumed.
    imageMean: 0                                                     # The assumed mean of the image values. 
    imageStd: 255                                                    # The assumed std of the image values.
    inputLayerName: input                                            # The label of the image input node.
    outputLayerName: MobilenetV2/Predictions/Reshape_1               # The label of the output node.
    labelsResource: classpath:/mobilenet_v2_labels.txt               # Path to resource with labels
    threshold: 0.1                                                   # Object detection threshold
  previewSize: 320                                                   # Width of the previews
  maxExecutorsCount: 10                                              # Executors pool size for images processing

server:
  servlet:
    session:
      timeout: 2m                                                    # Timeout for storing uploaded image previews in sessions 

Deploy as Docker container

Build container using profile docker:

$ ./mvnw clean package -Pdocker

Run container:

$ docker run -p 8081:8080 -t tensorboot

Or you can use script (by default, services are exposed on port 8081):

$ ./run-docker.sh

Deploy to Heroku

Note that app is memory intensive, so free nodes will complain

Login cli to Heroku:

$ heroku login

Create app:

$ heroku create

Rename app:

$ heroku apps:rename tensorboot

Limit memory (optional for free account)

$ heroku config:set JAVA_TOOL_OPTIONS="-Xmx300m"

Deploy app to Heroku:

$ ./mvnw clean heroku:deploy

Check app logs:

$ heroku logs --tail

Deploying to Pivotal Cloud Foundry

Build application distribution zip:

$ ./mvnw clean package -PdistZip

Login cli to Cloud Foundry:

$ cf login -a https://api.run.pivotal.io
API endpoint: https://api.run.pivotal.io

Email> <YOUR EMAIL>

Password> 
Authenticating...
OK
...

Push application:

$ cf push 

Check application status:

$ cf apps 

Delete application:

$ cf delete tensorboot 

TODO

  • More model options (text, audio, video examples)
  • Use browser camera to catch photos/audio/video
  • Add more configuration options and restrictions to simplify production deployment

License

Copyright (C) 2019 Oleksiy Grechanov

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

tensorboot's People

Contributors

grolex18 avatar

Watchers

James Cloos avatar Juan Pablo Prado 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.