In [1]:
from flask import Flask,request
from scipy import misc
import cv2
In [ ]:
import numpy as np
import pandas as pd
from keras.models import model_from_json
In [ ]:
app = Flask(__name__)
@app.route('/upload', methods=['POST'])
def upload():
f = request.files['file']
im = misc.imread(f)
resized_image=cv2.resize(im,(100,100))
img_arr=np.asarray(resized_image).reshape((1,resized_image.shape[1], resized_image.shape[0],3))
X_test = img_arr.astype('float32')
X_test_rescale=X_test/255
# load json and create model
json_file = open('cnn18.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("cnn18.h5")
y_pred_probas1 = loaded_model.predict(X_test_rescale)
y_pred = np.argmax(y_pred_probas1)
flower_dir={
0:'African_daisy',
1:'Cornflower',
2:'Ice_plant',
3:'Nigella',
4:'Peony',
5:'Ragged_robin',
6:'Soapwort',
7:'Spathiphyllum',
8:'Spring_beauty',
9:'Sunflower'}
result=flower_dir[y_pred]
result2='This is a ' + result +' image'
return result2
@app.route('/')
def index():
return '''
<!doctype html>
<html>
<body>
<form action='/upload' method='post' enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='submit' value='Upload'>
</form>
'''
if __name__ == '__main__':
app.run()
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: