Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

flask - CNN Model Deployment On Heroku 500 internal error while uploading image and sending for prediciton

I have deployed a CNN model using flask and Heroku. In a part of the code model requires an image which will gets save in a folder name uploads and then the path of the image is given to the model for prediction. When I run the model on my local machine It works find but on heroku it shows and 500 internal error maybe because of upload file issue. here is an glimpse of my upload function code.

def upload():
    if request.method == 'POST':
        # Get the file from post request
        f = request.files['file']

        # Save the file to ./uploads
        basepath = os.path.dirname(__file__)
        file_path = os.path.join(
            basepath, 'uploads', secure_filename(f.filename))
        f.save(file_path)
        print(file_path)

        # Make prediction
        preds = model_predict(file_path)
        return preds

according to me I have to do some changes in the way model predicts or may be something else. help me if you know the solution.

The image is only requires for one instance then there is no use of it so if there is a way using which I can load the image virtually and then deletes it, then it would be better

Heroku URL: https://banana-ripeness-detection.herokuapp.com/ Github URL: https://github.com/Abhayparashar31/brd

One More Thing When The Image Gets uploaded and sends for prediction it shows and 500 Internal Error.

A Glimpse of Heroku Logs

2021-02-04T17:00:34.077958+00:00 app[web.1]:     return self.finalize_request(rv)
2021-02-04T17:00:34.077959+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1831, in finalize_request
2021-02-04T17:00:34.077959+00:00 app[web.1]:     response = self.make_response(rv)
2021-02-04T17:00:34.077959+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1957, in make_response
2021-02-04T17:00:34.077961+00:00 app[web.1]:     'The view function did not return a valid response. The'
2021-02-04T17:00:34.077962+00:00 app[web.1]: TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
2021-02-04T17:00:34.079092+00:00 app[web.1]: 10.16.194.154 - - [04/Feb/2021:17:00:34 +0000] "GET /predict HTTP/1.1" 500 290 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36"
2021-02-04T17:00:34.081003+00:00 heroku[router]: at=info method=GET path="/predict" host=banana-ripeness-detection.herokuapp.com request_id=1e3cafa4-c7a4-4174-9155-1574add02f95 fwd="106.207.197.172" dyno=web.1 connect=1ms service=5ms status=500 bytes=455 protocol=https
2021-02-04T17:04:04.908537+00:00 app[web.1]: 10.30.91.53 - - [04/Feb/2021:17:04:04 +0000] "GET / HTTP/1.1" 200 1677 "https://dashboard.heroku.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36"
2021-02-04T17:04:04.909763+00:00 heroku[router]: at=info method=GET path="/" host=banana-ripeness-detection.herokuapp.com request_id=5a4a11a2-4505-4691-a4c6-a92a22b7b7e6 fwd="106.207.197.172" dyno=web.1 connect=0ms service=15ms status=200 bytes=1839 protocol=https

Thanks In Advance

question from:https://stackoverflow.com/questions/66056956/cnn-model-deployment-on-heroku-500-internal-error-while-uploading-image-and-send

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...