简体   繁体   English

Heroku 上的 OpenCV 错误,但模型成功部署

[英]OpenCV error on Heroku but model successfully deployed

I am trying to deploy a deep learning Flask app on Heroku.我正在尝试在 Heroku 上部署深度学习 Flask 应用程序。 It is successfully deployed, but still giving me the Application Error message.它已成功部署,但仍然给我Application Error消息。 I have checked the logs, but didn't find anything.我检查了日志,但没有找到任何东西。 Help me!帮我!

Build logs -构建日志 -

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/python
-----> Python app detected
-----> No Python version was specified. Using the same version as the last build: python-3.9.7
       To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes
-----> Requirements file has been changed, clearing cached dependencies
-----> Installing python-3.9.7
-----> Installing pip 21.3.1, setuptools 57.5.0 and wheel 0.37.0
-----> Installing SQLite3
-----> Installing requirements with pip
       Collecting Flask==1.1.2
         Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
        .
        .

Successfully installed Flask-1.1.2 Jinja2-2.10.1 MarkupSafe-1.1.1 Werkzeug-1.0.1 absl-py-0.15.0 astunparse-1.6.3 cachetools-4.2.4 certifi-2021.10.8 charset-normalizer-2.0.7 click-8.0.3 flatbuffers-1.12 gast-0.4.0 google-auth-2.3.3 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.34.1 gunicorn-20.0.4 h5py-3.1.0 idna-3.3 itsdangerous-1.1.0 keras-nightly-2.5.0.dev2021032900 keras-preprocessing-1.1.2 markdown-3.3.4 numpy-1.19.5 oauthlib-3.1.1 opencv-python-4.5.3.56 opt-einsum-3.3.0 protobuf-3.19.1 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.26.0 requests-oauthlib-1.3.0 rsa-4.7.2 six-1.15.0 tensorboard-2.7.0 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.0 tensorflow-cpu-2.5.0 tensorflow-estimator-2.5.0 termcolor-1.1.0 tqdm-4.59.0 typing-extensions-3.7.4.3 urllib3-1.26.7 wrapt-1.12.1
-----> Discovering process types
       Procfile declares types -> web
-----> Compressing...
       Done: 439.1M
-----> Launching...
 !     Warning: Your slug size (439 MB) exceeds our soft limit (300 MB) which may affect boot time.
       Released v4
       https://image-captionss.herokuapp.com/ deployed to Heroku

Here is my app.py -这是我的app.py -

app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 1

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

@app.route('/after', methods = ['GET', 'POST'])
def after():

    global model, resnet, vocab, inv_vocab

    img = request.files['file1']
    img.save('static/file.jpg')

    print("=" * 50)
    print("IMAGE SAVED")

    
    image = cv2.imread('static/file.jpg')
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    image = cv2.resize(image, (224, 224))
    image = np.reshape(image, (1, 224, 224, 3))

    incept = resnet.predict(image).reshape(1, 2048)

    print("=" * 50)
    print("Predict Features")
    
    text_in = ['startofseq']
    final = ''
    
    count = 0
    while tqdm(count < 20):
        count += 1
        encoded = []
        for i in text_in:
            encoded.append(vocab[i])
            
        padded = pad_sequences([encoded], maxlen = 36, padding = 'post', truncating = 'post')
        sampled_index = np.argmax(model.predict([incept, padded]))
        sampled_word = inv_vocab[sampled_index]
        
        if sampled_word != 'endofseq':
            final = final + ' ' + sampled_word
        
        text_in.append(sampled_word)       
    return render_template('after.html', data = final)

if __name__ == "__main__":
    app.run(debug=True)

Here is my GitHub repo - LINK这是我的 GitHub 存储库 -链接

My applications logs:我的应用程序日志:

2021-11-08T06:11:59.657691+00:00 app[web.1]:   File "app.py", line 1, in <module>
2021-11-08T06:11:59.657772+00:00 app[web.1]:     import cv2
2021-11-08T06:11:59.657781+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.8/site-packages/cv2/__init__.py", line 5, in <module>
2021-11-08T06:11:59.657862+00:00 app[web.1]:     from .cv2 import *
2021-11-08T06:11:59.657876+00:00 app[web.1]: ImportError: libGL.so.1: cannot open shared object file: No such file or directory
2021-11-08T06:11:59.842143+00:00 heroku[web.1]: Process exited with status 1
2021-11-08T06:11:59.906506+00:00 heroku[web.1]: State changed from starting to crashed
2021-11-08T06:12:08.000000+00:00 app[api]: Build succeeded
2021-11-08T06:12:11.971382+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=image-captionss.herokuapp.com request_id=bc6b146e-11bb-407e-a861-ba9244a954e3 fwd="152.57.22.102" dyno= connect= service= status=503 bytes= protocol=https
2021-11-08T06:12:12.623298+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=image-captionss.herokuapp.com request_id=74968483-821f-459c-b317-b7e02e8a5c82 fwd="152.57.22.102" dyno= connect= service= status=503 bytes= protocol=https

This error has been solved by changing this line on requirements.txt :此错误已通过更改requirements.txt上的这一行得到解决:

opencv-python==4.2.0

to

opencv-python-headless==4.2.0.32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 成功部署 Django 到 Heroku 但收到应用程序错误 - Successfully deployed Django to Heroku but received application error Heroku 应用部署成功但应用报错 - Heroku app deployed successfully but Application Error 我在 Heroku 上成功部署了我的 Web 应用程序,但显示应用程序错误 - I successfully deployed my web app on Heroku but shows Application Error Streamlit Python 应用程序已成功部署到 Heroku,但出现应用程序错误 - Streamlit Python app deployed successfully to Heroku, but I get an application error Heroku 应用程序成功部署,但打开应用程序时收到应用程序错误 - Heroku app successfully deployed, but receiving application error when opening app Heroku上的Django应用程序,已成功部署但无法提供服务 - Django app on Heroku, deployed successfully but could not be served 应用程序(Python Django,PostgreSql)已成功部署在Heroku上,但是尝试打开时出现错误 - App (Python Django, PostgreSql) is deployed successfully on Heroku, but I'm getting error when trying to open 在已部署的 Flask 应用程序 (Heroku) 上使用 OpenCV - Use OpenCV on deployed Flask app (Heroku) Heroku 成功部署,但我仍然没有运行任何 web 进程 - Heroku successfully deployed but I still keep getting no web process running Flask 应用程序部署成功 - 应用程序错误 - Flask app deployed successfully - Application Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM