Как я могу решить вопрос об ошибке heroku Flask H10 в моем веб-приложении opencv - PullRequest
0 голосов
/ 24 апреля 2020

В последнее время я создал приложение OpenCV Flask. Оно работает отлично. Работает локально, могу выложить Pu sh в Heroku, но когда я открываю веб-сайт, я получаю сообщение об ошибке приложения, проверяя журналы, вот что я получил

2020-04-24T16:55:36.511541+00:00 heroku[web.1]: State changed from crashed to starting
2020-04-24T16:55:57.615077+00:00 app[web.1]: [2020-04-24 16:55:57 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-04-24T16:55:57.615639+00:00 app[web.1]: [2020-04-24 16:55:57 +0000] [4] [INFO] Listening at: http://0.0.0.0:51734 (4)
2020-04-24T16:55:57.615734+00:00 app[web.1]: [2020-04-24 16:55:57 +0000] [4] [INFO] Using worker: sync
2020-04-24T16:55:57.620023+00:00 app[web.1]: [2020-04-24 16:55:57 +0000] [10] [INFO] Booting worker with pid: 10
2020-04-24T16:55:57.624198+00:00 app[web.1]: [2020-04-24 16:55:57 +0000] [11] [INFO] Booting worker with pid: 11
2020-04-24T16:55:58.011708+00:00 app[web.1]: [2020-04-24 16:55:58 +0000] [11] [ERROR] Exception in worker process
2020-04-24T16:55:58.011714+00:00 app[web.1]: Traceback (most recent call last):
2020-04-24T16:55:58.011715+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-04-24T16:55:58.011716+00:00 app[web.1]: worker.init_process()
2020-04-24T16:55:58.011716+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-04-24T16:55:58.011716+00:00 app[web.1]: self.load_wsgi()
2020-04-24T16:55:58.011717+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-04-24T16:55:58.011717+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-04-24T16:55:58.011718+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-04-24T16:55:58.011718+00:00 app[web.1]: self.callable = self.load()
2020-04-24T16:55:58.011719+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-04-24T16:55:58.011719+00:00 app[web.1]: return self.load_wsgiapp()
2020-04-24T16:55:58.011719+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-04-24T16:55:58.011720+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-04-24T16:55:58.011720+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-04-24T16:55:58.011720+00:00 app[web.1]: mod = importlib.import_module(module)
2020-04-24T16:55:58.011721+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-04-24T16:55:58.011722+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-04-24T16:55:58.011723+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-04-24T16:55:58.011723+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-04-24T16:55:58.011723+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2020-04-24T16:55:58.011723+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2020-04-24T16:55:58.011724+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2020-04-24T16:55:58.011724+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-04-24T16:55:58.011724+00:00 app[web.1]: File "/app/app.py", line 3, in <module>
2020-04-24T16:55:58.011725+00:00 app[web.1]: import cv2
2020-04-24T16:55:58.011725+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/cv2/__init__.py", line 5, in <module>
2020-04-24T16:55:58.011725+00:00 app[web.1]: from .cv2 import *
2020-04-24T16:55:58.011726+00:00 app[web.1]: ImportError: libSM.so.6: cannot open shared object file: No such file or directory
2020-04-24T16:55:58.011806+00:00 app[web.1]: [2020-04-24 16:55:58 +0000] [10] [ERROR] Exception in worker process
2020-04-24T16:55:58.011806+00:00 app[web.1]: Traceback (most recent call last):
2020-04-24T16:55:58.011807+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-04-24T16:55:58.011807+00:00 app[web.1]: worker.init_process()
2020-04-24T16:55:58.011807+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-04-24T16:55:58.011808+00:00 app[web.1]: self.load_wsgi()
2020-04-24T16:55:58.011808+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-04-24T16:55:58.011809+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-04-24T16:55:58.011809+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-04-24T16:55:58.011809+00:00 app[web.1]: self.callable = self.load()
2020-04-24T16:55:58.011810+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-04-24T16:55:58.011810+00:00 app[web.1]: return self.load_wsgiapp()
2020-04-24T16:55:58.011810+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-04-24T16:55:58.011810+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-04-24T16:55:58.011811+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-04-24T16:55:58.011811+00:00 app[web.1]: mod = importlib.import_module(module)
2020-04-24T16:55:58.011811+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-04-24T16:55:58.011811+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-04-24T16:55:58.011812+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-04-24T16:55:58.011812+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-04-24T16:55:58.011812+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2020-04-24T16:55:58.011812+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2020-04-24T16:55:58.011813+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2020-04-24T16:55:58.011813+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-04-24T16:55:58.011813+00:00 app[web.1]: File "/app/app.py", line 3, in <module>
2020-04-24T16:55:58.011813+00:00 app[web.1]: import cv2
2020-04-24T16:55:58.011814+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/cv2/__init__.py", line 5, in <module>
2020-04-24T16:55:58.011814+00:00 app[web.1]: from .cv2 import *
2020-04-24T16:55:58.011816+00:00 app[web.1]: ImportError: libSM.so.6: cannot open shared object file: No such file or directory
2020-04-24T16:55:58.012100+00:00 app[web.1]: [2020-04-24 16:55:58 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-04-24T16:55:58.012263+00:00 app[web.1]: [2020-04-24 16:55:58 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-04-24T16:55:58.055855+00:00 app[web.1]: Traceback (most recent call last):
2020-04-24T16:55:58.055863+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 209, in run
2020-04-24T16:55:58.056203+00:00 app[web.1]: self.sleep()
2020-04-24T16:55:58.056208+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 357, in sleep
2020-04-24T16:55:58.056495+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
2020-04-24T16:55:58.056495+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-04-24T16:55:58.056692+00:00 app[web.1]: self.reap_workers()
2020-04-24T16:55:58.056711+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-04-24T16:55:58.057002+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-04-24T16:55:58.057046+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-04-24T16:55:58.057049+00:00 app[web.1]:
2020-04-24T16:55:58.057050+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-04-24T16:55:58.057050+00:00 app[web.1]:
2020-04-24T16:55:58.057052+00:00 app[web.1]: Traceback (most recent call last):
2020-04-24T16:55:58.057071+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 8, in <module>
2020-04-24T16:55:58.057175+00:00 app[web.1]: sys.exit(run())
2020-04-24T16:55:58.057196+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
2020-04-24T16:55:58.057319+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2020-04-24T16:55:58.057321+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 228, in run
2020-04-24T16:55:58.057498+00:00 app[web.1]: super().run()
2020-04-24T16:55:58.057500+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
2020-04-24T16:55:58.057636+00:00 app[web.1]: Arbiter(self).run()
2020-04-24T16:55:58.057728+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 229, in run
2020-04-24T16:55:58.057912+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2020-04-24T16:55:58.057913+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 342, in halt
2020-04-24T16:55:58.058124+00:00 app[web.1]: self.stop()
2020-04-24T16:55:58.058128+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
2020-04-24T16:55:58.058454+00:00 app[web.1]: time.sleep(0.1)
2020-04-24T16:55:58.058458+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-04-24T16:55:58.058643+00:00 app[web.1]: self.reap_workers()
2020-04-24T16:55:58.058647+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-04-24T16:55:58.058943+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-04-24T16:55:58.058947+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-04-24T16:55:58.158710+00:00 heroku[web.1]: State changed from starting to crashed

это мой Procfile

web: gunicorn app:app

это мое приложение

import os
from flask import Flask, render_template, request
import cv2
import numpy as np
import base64

app = Flask(__name__)

UPLOAD_FOLDER = os.path.basename('uploads')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

@app.route("/")
def start_page():
    print("Start")
    return render_template('home.html')

@app.route('/upload', methods=['POST'])
def upload_file():
    file = request.files['image']

    # Save file
    #filename = 'static/' + file.filename
    #file.save(filename)

    # Read image
    image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_UNCHANGED)

    # Detect faces
    faces = detect_faces(image)

    if len(faces) == 0:
        faceDetected = False
        num_faces = 0
        to_send = ''
    else:
        faceDetected = True
        num_faces = len(faces)

        # Draw a rectangle
        for item in faces:
            draw_rectangle(image, item['rect'])

        # Save
        #cv2.imwrite(filename, image)

        # In memory
        image_content = cv2.imencode('.jpg', image)[1].tostring()
        encoded_image = base64.encodestring(image_content)
        to_send = 'data:image/jpg;base64, ' + str(encoded_image, 'utf-8')

    return render_template('home.html', faceDetected=faceDetected, num_faces=num_faces, image_to_show=to_send, init=True)

# ----------------------------------------------------------------------------------
# Detect faces using OpenCV
# ----------------------------------------------------------------------------------  
def detect_faces(img):
    '''Detect face in an image'''

    faces_list = []

    # Convert the test image to gray scale (opencv face detector expects gray images)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Load OpenCV face detector (LBP is faster)
    face_cascade = cv2.CascadeClassifier('assets/cascade.xml')

    # Detect multiscale images (some images may be closer to camera than others)
    # result is a list of faces
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5);

    # If not face detected, return empty list  
    if  len(faces) == 0:
        return faces_list

    for i in range(0, len(faces)):
        (x, y, w, h) = faces[i]
        face_dict = {}
        face_dict['face'] = gray[y:y + w, x:x + h]
        face_dict['rect'] = faces[i]
        faces_list.append(face_dict)

    # Return the face image area and the face rectangle
    return faces_list
# ----------------------------------------------------------------------------------
# Draw rectangle on image
# according to given (x, y) coordinates and given width and heigh
# ----------------------------------------------------------------------------------
def draw_rectangle(img, rect):
    '''Draw a rectangle on the image'''
    (x, y, w, h) = rect
    cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 255), 2)

if __name__ == "__main__":
    # Only for debugging while developing
    app.run(debug=True)

requiremnts.txt

audioread==2.1.8
cffi==1.14.0
click==7.1.1
decorator==4.4.2
Flask==1.1.2
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.2
joblib==0.14.1
librosa==0.7.2
llvmlite==0.32.0
MarkupSafe==1.1.1
numba==0.49.0
numpy==1.18.3
opencv-python==4.2.0.34
pandas==1.0.3
pycparser==2.20
python-dateutil==2.8.1
pytz==2019.3
resampy==0.2.2
scikit-learn==0.22.2.post1
scipy==1.4.1
six==1.14.0
SoundFile==0.10.3.post1
Werkzeug==1.0.1

наконец-то это мой HTML файл

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Face detection</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>

<div>
  <h1><b><p align="center">Face Detection With OpenCV</p></b></h1>
</div>


<header class="navbar">
    <form action="/upload" method="POST" enctype="multipart/form-data" >
        <div align="center">
            <label class="btn btn-default btn-file">
            <div align="center">
               <input type="file" class="custom-file-input" name="image" id="image" onchange="readURL(this);" />
            </div>
            <br>
            <img src="" id="blah" >
            </label>
        </div>  

        <hr>

        <div align="center">    
            <input type="submit" value="Upload your image" class="btn btn-primary">
        </div>
    </form>
</header>

<div class="text-center">
    {% if init %}
        {% if faceDetected %}
            <div class="alert alert-success" style="margin-top:20px;">
                <strong>Yes!</strong> {{ num_faces }} face(s) detected!
                <hr>
                <img src="{{ image_to_show }}">
            </div>    
        {% else %}
            <div class="alert alert-danger" style="margin-top:18px;">
                <strong>Nope!</strong> No face detected
            </div>
        {% endif %}
    {% endif %}
</div>

</body>
</html>

Я знаю, что это очень трудно проверить, или, по крайней мере, я так думаю. Было бы очень полезно, если кто-то обнаружит эту проблему, я попробовал другие вопросы типа ошибки H10 в Интернете но ничего не помогло, пожалуйста, решите эту проблему

Спасибо

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...