![](/img/trans.png)
[英]Problem loading Tensorflow Keras Model in Heroku deployment using Flask
[英]Deployment of classification model using Flask
我正在嘗試使用 Flask 部署經過訓練的放射圖像分類模型。 但我收到“內部應用程序錯誤”錯誤消息但是當我運行主機時出現以下錯誤。 下面是 index.html,前端,我可以從中獲取輸入圖像進行分類。 那么你能不能幫我找到從我的 index.html 獲取輸入圖像的方法並通過我的代碼進行預測
<!DOCTYPE html> <html> <head> <title>File Upload Box</title> </head> <body> <h3><b><u><center>Classification of Radiological images using Convolution Neural Network</center></u></b></h3> <form action="/index" method="POST"> <input type = "file" name = "fileupload" accept "image/*" /> <center> <button type="button">Get Prediction!</button> </center> </form> </body> </html>
下面是我的 app.py 燒瓶腳本
def generate_prediction(input):
model=load_model('./models/model.h5')
#Normalizing the inputs
IMG_SIZE = 100
img_array = cv2.imread(input, cv2.IMREAD_GRAYSCALE)
img_array = img_array/255.0
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
input = new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1)
#input=(input-mean)/std
pred= model.predict(input)
pred = list(pred[0])
return pred
@app.route('/', methods = ['GET'])
def home():
return render_template('index.html')
@app.route('/get_price', methods=['POST'])
def get_price():
CATEGORIES = ["Brain", "Hands", "Kidney", "Legs", "Lungs", "Skull", "Teeth"]
K.clear_session()
input=request.form.to_dict()
#input=np.array(list(input.values()))
prediction=generate_prediction(input)
return CATEGORIES[prediction.index(max(prediction))]
#print(max(prediction)*100)
if __name__ == '__main__':
#app.debug = True
app.run(host='192.168.72.1',port=5000)
你的表格應該是
<form action="/get_price" method="POST" enctype="multipart/form-data">
<input type = "file" name = "fileupload" accept "image/*" />
<center>
<button type="button">Get Prediction!</button>
</center>
</form>
要獲取控制器內部的圖像,請執行以下操作
@app.route('/get_price', methods=['POST'])
def get_price():
CATEGORIES = ["Brain", "Hands", "Kidney", "Legs", "Lungs", "Skull", "Teeth"]
K.clear_session()
# like this you will only get the File object you uploaded
input = request.files.get('fileupload', None)
prediction=generate_prediction(input)
return CATEGORIES[prediction.index(max(prediction))]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.