Skip to content

Commit 37abcd2

Browse files
authored
Merge pull request #61 from Azure-Samples/UpgradingToLatestCustomVisionDockerImage
Upgrading to latest custom vision docker image
2 parents 40c8d24 + 33dcda6 commit 37abcd2

File tree

15 files changed

+324
-278
lines changed

15 files changed

+324
-278
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
55

66
# User-specific files
7+
*.env
78
*.suo
89
*.user
910
*.userosscache

modules/CameraCapture/app/CameraCapture.py

Lines changed: 83 additions & 114 deletions
Large diffs are not rendered by default.

modules/CameraCapture/module.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"image": {
55
"repository": "$CONTAINER_REGISTRY_ADDRESS/cameracapture",
66
"tag": {
7-
"version": "0.2.8",
7+
"version": "0.2.11",
88
"platforms": {
99
"amd64": "./amd64.Dockerfile",
1010
"arm32v7": "./arm32v7.Dockerfile",
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
FROM tensorflow/tensorflow:latest-py3
1+
FROM python:3.7-slim
22

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

5-
COPY /build/amd64-requirements.txt amd64-requirements.txt
6-
7-
# Install Python packages
8-
RUN pip install -r amd64-requirements.txt
9-
10-
ADD app /app
6+
COPY app /app
117

128
# Expose the port
139
EXPOSE 80
@@ -16,4 +12,4 @@ EXPOSE 80
1612
WORKDIR /app
1713

1814
# Run the flask server for the endpoints
19-
CMD python app.py
15+
CMD python -u app.py

modules/ImageClassifierService/app/app.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,75 @@
44
import io
55

66
# Imports for the REST API
7-
from flask import Flask, request
7+
from flask import Flask, request, jsonify
88

99
# Imports for image procesing
1010
from PIL import Image
11-
#import scipy
12-
#from scipy import misc
1311

1412
# Imports for prediction
1513
from predict import initialize, predict_image, predict_url
1614

1715
app = Flask(__name__)
1816

1917
# 4MB Max image size limit
20-
app.config['MAX_CONTENT_LENGTH'] = 4 * 1024 * 1024
18+
app.config['MAX_CONTENT_LENGTH'] = 4 * 1024 * 1024
2119

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

2725
# Like the CustomVision.ai Prediction service /image route handles either
28-
# - octet-stream image file
26+
# - octet-stream image file
2927
# - a multipart/form-data with files in the imageData parameter
3028
@app.route('/image', methods=['POST'])
31-
def predict_image_handler():
29+
@app.route('/<project>/image', methods=['POST'])
30+
@app.route('/<project>/image/nostore', methods=['POST'])
31+
@app.route('/<project>/classify/iterations/<publishedName>/image', methods=['POST'])
32+
@app.route('/<project>/classify/iterations/<publishedName>/image/nostore', methods=['POST'])
33+
@app.route('/<project>/detect/iterations/<publishedName>/image', methods=['POST'])
34+
@app.route('/<project>/detect/iterations/<publishedName>/image/nostore', methods=['POST'])
35+
def predict_image_handler(project=None, publishedName=None):
3236
try:
3337
imageData = None
3438
if ('imageData' in request.files):
3539
imageData = request.files['imageData']
40+
elif ('imageData' in request.form):
41+
imageData = request.form['imageData']
3642
else:
3743
imageData = io.BytesIO(request.get_data())
3844

39-
#img = scipy.misc.imread(imageData)
4045
img = Image.open(imageData)
4146
results = predict_image(img)
42-
return json.dumps(results)
47+
return jsonify(results)
4348
except Exception as e:
4449
print('EXCEPTION:', str(e))
4550
return 'Error processing image', 500
4651

4752

4853
# Like the CustomVision.ai Prediction service /url route handles url's
4954
# in the body of hte request of the form:
50-
# { 'Url': '<http url>'}
55+
# { 'Url': '<http url>'}
5156
@app.route('/url', methods=['POST'])
52-
def predict_url_handler():
57+
@app.route('/<project>/url', methods=['POST'])
58+
@app.route('/<project>/url/nostore', methods=['POST'])
59+
@app.route('/<project>/classify/iterations/<publishedName>/url', methods=['POST'])
60+
@app.route('/<project>/classify/iterations/<publishedName>/url/nostore', methods=['POST'])
61+
@app.route('/<project>/detect/iterations/<publishedName>/url', methods=['POST'])
62+
@app.route('/<project>/detect/iterations/<publishedName>/url/nostore', methods=['POST'])
63+
def predict_url_handler(project=None, publishedName=None):
5364
try:
54-
image_url = json.loads(request.get_data())['Url']
65+
image_url = json.loads(request.get_data().decode('utf-8'))['url']
5566
results = predict_url(image_url)
56-
return json.dumps(results)
67+
return jsonify(results)
5768
except Exception as e:
5869
print('EXCEPTION:', str(e))
5970
return 'Error processing image'
6071

61-
6272
if __name__ == '__main__':
6373
# Load and intialize the model
6474
initialize()
6575

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

0 commit comments

Comments
 (0)