-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
84 lines (60 loc) · 1.86 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Flask
from flask import Flask , request, render_template, jsonify
from tensorflow.keras.models import load_model
import cv2
# Some utilites
import numpy as np
from util import base64_to_pil
# Declare a flask app
app = Flask(__name__)
print('Model loaded. Check http://127.0.0.1:5002/')
#add your model_path
model_path = '/home/chirag/ML_Model/skin.h5'
# Load your own trained model
model = load_model(model_path)
model._make_predict_function() # Necessary
print('Model loaded. Start serving...')
def model_predict(img, model):
collecter = cv2.cvtColor(np.float32(img), cv2.COLOR_BGR2GRAY)
resize_img = cv2.resize(collecter, (128, 128))
final_img = np.array(resize_img)
final_img = final_img.astype('float32')
final_img /= 255
extend_imgDims = np.expand_dims(final_img, axis=2)
test_img = np.expand_dims(extend_imgDims, axis=0)
index_id = model.predict(test_img)
lable = np.argmax(index_id)
return lable
@app.route('/', methods=['GET'])
def index():
# Main page
return render_template('index.html')
@app.route('/predict', methods=['GET', 'POST'])
def predict():
if request.method == 'POST':
# Get the image from post request
img = base64_to_pil(request.json)
# Make prediction
preds = model_predict(img, model)
if preds==0:
result="MEL"
elif preds==1:
result="NV"
elif preds==2:
result="BCC"
elif preds == 3:
result = "AK"
elif preds==4:
result="BKL"
elif preds==5:
result="DF"
elif preds ==6:
result = "VASC"
elif preds ==7:
result = "SCC"
else :
result = "UNK"
return jsonify(result=result, probability=int(preds))
return None
if __name__ == '__main__':
app.run(port=5002, threaded=False)