Can model.h5 file be accessed at the backend using load_model from Keras library?

Question:

I have saved my model after training and am currently loading it to use it for prediction at the backend. I have uploaded the model.h5 file to heroku via Github using auto-deploy feature with the flask app associated to it accessing it when the predict method is called. It works fine when testing it on localhost, but is not able to run the line with load_model when deployed and used to heroku.

The below line gives the error (observed from backend logs).

model = load_model('model.h5')

Error message :

2022-11-06T11:17:57.423658+00:00 app[web.1]: Predict parameter : image_picker5679010659167792600.jpg
2022-11-06T11:17:57.820210+00:00 app[web.1]: Retrieved image from S3
2022-11-06T11:17:57.822053+00:00 app[web.1]: [2022-11-06 11:17:57,821] ERROR in app: Exception on /predict/image_picker5679010659167792600.jpg [GET]
2022-11-06T11:17:57.822053+00:00 app[web.1]: Traceback (most recent call last):
2022-11-06T11:17:57.822054+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/flask/app.py", line 2525, in wsgi_app
2022-11-06T11:17:57.822054+00:00 app[web.1]: response = self.full_dispatch_request()
2022-11-06T11:17:57.822054+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/flask/app.py", line 1822, in full_dispatch_request
2022-11-06T11:17:57.822055+00:00 app[web.1]: rv = self.handle_user_exception(e)
2022-11-06T11:17:57.822055+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/flask/app.py", line 1820, in full_dispatch_request
2022-11-06T11:17:57.822055+00:00 app[web.1]: rv = self.dispatch_request()
2022-11-06T11:17:57.822056+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/flask/app.py", line 1796, in dispatch_request
2022-11-06T11:17:57.822056+00:00 app[web.1]: return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
2022-11-06T11:17:57.822056+00:00 app[web.1]: File "/app/app.py", line 70, in predict
2022-11-06T11:17:57.822056+00:00 app[web.1]: model = load_model('model.h5')

Is there any way to access .h5 files at the backend or is there any other way to get around it ?

Asked By: Sai Gruheeth

||

Answers:

To everyone having this issue, Heroku doesn’t support large file systems associated with Git-LFS(more than 300MB in Heroku). So accessing your .h5 file from your flask app won’t help as .h5 files are usually huge. So, this application won’t work on Heroku.

Answered By: Sai Gruheeth
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.