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.
To build the project, you need to have these installed: JDK 8+ - download it from here.
Required before builds/deployment
Model will be stored under model folder.
Also you can use downloadModel maven profile to download model during build:
$ ./mvnw clean install -PdownloadModel
To build the project, run:
$ ./mvnw clean install
Possible parameters for script are:
Usage: ./run.sh [-c -d] -c Recompile project -d Enable debug
Main application page: http://localhost:8080/
UI file upload page: http://localhost:8080/uploadForm
Rest services are deployed under http://localhost:8080/TensorApi context
All REST services have their definitions exposed using Swagger. Once the demo is running locally you can access Swagger using these URLS:
Application is configured to log to console and into file. You can find daily rolling log files under "log" folder.
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
Build container using profile docker:
$ ./mvnw clean package -Pdocker
$ docker run -p 8081:8080 -t tensorboot
Or you can use script (by default, services are exposed on port 8081):
Note that app is memory intensive, so free nodes will complain
Login cli to Heroku:
$ heroku login
$ heroku create
$ 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
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 ...
$ cf push
Check application status:
$ cf apps
$ cf delete tensorboot
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
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.