在Heroku上部署Flask应用程序时,在日志中显示应用程序崩溃

时间:2020-08-06 07:10:43

标签: python flask heroku deploying

这是我第一次使用Heroku服务。我正在尝试在Heroku上部署Image Classifier flask应用程序。我已经从其他职位获得帮助,但到目前为止没有任何结果。它可以在本地计算机上完美运行。

文件结构:

ImageClassifier_DeepLearning
 |
 + static
 |      |
 |      + style.css
 |
 + templates
 |       |
 |       + index.html
 |       + index2.html
 |       + show.html
 |       + upload.html
 |
 + uploads
 |       | 
 |       +.jpg,.jpeg ....
 |
 + Procfile
 |
 + requirements.txt
 |
 + app.py
 |
 + model2.h5

Procfile:

web: gunicorn --bind 0.0.0.0:$PORT app: app

requirements.txt:

gunicorn==20.0.4
keras
numpy==1.18.5
h5py==2.10.0
pillow==7.1.2
flask_uploads
Flask==1.1.2
protobuf>=3.8.0
tensorflow==1.0.0
Werkzeug==1.0.1
scipy==1.4.1
scikit-image==0.16.2
setuptools>=41.0.0

这是从日志中获取的错误的快照: enter image description here

heroku ps:

enter image description here

如果有任何人能提供帮助,谢谢!:)

app.py

import tensorflow as tf
import keras
from flask import Flask, render_template, request
from flask_uploads import UploadSet, configure_uploads,IMAGES
from scipy.misc import imsave, imread, imresize
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
from tensorflow.keras.models import load_model

import numpy as np
from werkzeug import secure_filename
import keras.models
import re
import sys
import os

app = Flask(__name__)

model = load_model('model2.h5')
model.compile(loss='categorical_crossentropy',optimizer='adam',metrics=['accuracy'])

global graph
graph = tf.compat.v1.get_default_graph()

photos = UploadSet('photos', IMAGES)

app.config['UPLOADED_PHOTOS_DEST'] = '.'
configure_uploads(app, photos)

def preprocess_image(file_path):
    img = image.load_img(file_path, target_size=(224,224))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)
    x = preprocess_input(x)
    return x

@app.route('/')
def index():
    return render_template("index.html")

@app.route('/upload', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST':
        f = request.files['photo']

        basepath = os.path.dirname(__file__)
        file_path = os.path.join(
            basepath, 'uploads', secure_filename(f.filename))
        f.save(file_path)

        x = preprocess_image(file_path)

        out = model.predict(x)
        u = decode_predictions(out, top=3)[0]
        s1 = u[0][1]
        s2 = u[0][2]*100
        s3 = u[1][1]
        s4 = u[1][2]*100
        s5 = u[2][1]
        s6 = u[2][2]*100
        print(s1,s2,s3)
        return render_template("index2.html",s1=s1,s2=s2,s3=s3,s4=s4,s5=s5,s6=s6)

if __name__ == "__main__":
    port = int(os.environ.get('PORT', 8080))
    app.run(host='0.0.0.0', port=port)

完整日志: enter image description here

0 个答案:

没有答案