Skip to content

Commit

Permalink
using latest custom vision image
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Bertrand committed Dec 10, 2019
1 parent d6a91e8 commit 33dcda6
Show file tree
Hide file tree
Showing 14 changed files with 323 additions and 278 deletions.
197 changes: 83 additions & 114 deletions modules/CameraCapture/app/CameraCapture.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/CameraCapture/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"image": {
"repository": "$CONTAINER_REGISTRY_ADDRESS/cameracapture",
"tag": {
"version": "0.2.8",
"version": "0.2.11",
"platforms": {
"amd64": "./amd64.Dockerfile",
"arm32v7": "./arm32v7.Dockerfile",
Expand Down
14 changes: 5 additions & 9 deletions modules/ImageClassifierService/amd64.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
FROM tensorflow/tensorflow:latest-py3
FROM python:3.7-slim

RUN echo "BUILD MODULE: ImageClassifierService"
RUN pip install -U pip
RUN pip install numpy==1.17.3 tensorflow==2.0.0 flask pillow

COPY /build/amd64-requirements.txt amd64-requirements.txt

# Install Python packages
RUN pip install -r amd64-requirements.txt

ADD app /app
COPY app /app

# Expose the port
EXPOSE 80
Expand All @@ -16,4 +12,4 @@ EXPOSE 80
WORKDIR /app

# Run the flask server for the endpoints
CMD python app.py
CMD python -u app.py
37 changes: 24 additions & 13 deletions modules/ImageClassifierService/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,75 @@
import io

# Imports for the REST API
from flask import Flask, request
from flask import Flask, request, jsonify

# Imports for image procesing
from PIL import Image
#import scipy
#from scipy import misc

# Imports for prediction
from predict import initialize, predict_image, predict_url

app = Flask(__name__)

# 4MB Max image size limit
app.config['MAX_CONTENT_LENGTH'] = 4 * 1024 * 1024
app.config['MAX_CONTENT_LENGTH'] = 4 * 1024 * 1024

# Default route just shows simple text
@app.route('/')
def index():
return 'CustomVision.ai model host harness'

# Like the CustomVision.ai Prediction service /image route handles either
# - octet-stream image file
# - octet-stream image file
# - a multipart/form-data with files in the imageData parameter
@app.route('/image', methods=['POST'])
def predict_image_handler():
@app.route('/<project>/image', methods=['POST'])
@app.route('/<project>/image/nostore', methods=['POST'])
@app.route('/<project>/classify/iterations/<publishedName>/image', methods=['POST'])
@app.route('/<project>/classify/iterations/<publishedName>/image/nostore', methods=['POST'])
@app.route('/<project>/detect/iterations/<publishedName>/image', methods=['POST'])
@app.route('/<project>/detect/iterations/<publishedName>/image/nostore', methods=['POST'])
def predict_image_handler(project=None, publishedName=None):
try:
imageData = None
if ('imageData' in request.files):
imageData = request.files['imageData']
elif ('imageData' in request.form):
imageData = request.form['imageData']
else:
imageData = io.BytesIO(request.get_data())

#img = scipy.misc.imread(imageData)
img = Image.open(imageData)
results = predict_image(img)
return json.dumps(results)
return jsonify(results)
except Exception as e:
print('EXCEPTION:', str(e))
return 'Error processing image', 500


# Like the CustomVision.ai Prediction service /url route handles url's
# in the body of hte request of the form:
# { 'Url': '<http url>'}
# { 'Url': '<http url>'}
@app.route('/url', methods=['POST'])
def predict_url_handler():
@app.route('/<project>/url', methods=['POST'])
@app.route('/<project>/url/nostore', methods=['POST'])
@app.route('/<project>/classify/iterations/<publishedName>/url', methods=['POST'])
@app.route('/<project>/classify/iterations/<publishedName>/url/nostore', methods=['POST'])
@app.route('/<project>/detect/iterations/<publishedName>/url', methods=['POST'])
@app.route('/<project>/detect/iterations/<publishedName>/url/nostore', methods=['POST'])
def predict_url_handler(project=None, publishedName=None):
try:
image_url = json.loads(request.get_data())['Url']
image_url = json.loads(request.get_data().decode('utf-8'))['url']
results = predict_url(image_url)
return json.dumps(results)
return jsonify(results)
except Exception as e:
print('EXCEPTION:', str(e))
return 'Error processing image'


if __name__ == '__main__':
# Load and intialize the model
initialize()

# Run the server
app.run(host='0.0.0.0', port=80)

Loading

0 comments on commit 33dcda6

Please sign in to comment.