Home > other >  Application Error on Heroku but model successfully deployed
Application Error on Heroku but model successfully deployed

Time:11-10

I am trying to deploy a deep learning Flask app on Heroku. It is successfully deployed, but still giving me the Application Error message. 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 = 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

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

CodePudding user response:

This error has been solved by changing this line on requirements.txt:

opencv-python==4.2.0

to

opencv-python-headless==4.2.0.32
  • Related