Flask 웹 서버에서 저장한 모델 불러오기
import flask
from flask import Flask, request, render_template
import numpy as np
from scipy import misc
from keras.models import load_model
app = Flask(__name__)
@app.route("/")
@app.route("/index")
def index():
return flask.render_template('index.html')
@app.route("/predict", methods=['POST'])
def make_predecion():
if request.method == 'POST':
file = request.files['image']
if not file:
return render_template('index.html', label="No Files")
img = misc.imread(file)
img = img[:, :, :3]
img = img.reshape(1, -1)
prediction = model. predict(img)
label = str(np.squeeze(prediction))
return render_template('index.html', label=label)
if __name__ == '__main__':
model = load_model('my_model1.h5')
app.run(host='0.0.0.0', port=8000, debug=True)