FileNotFoundError while deploying Flask Rest API

I have been trying to deploy a REST API (POST) made in Flask (Python). The API basically takes X-Ray Images as input and then outputs whether it is infected by pneumonia or not. For carrying out this task, I have used the pickle file of a previously trained model, but due to some reason while deploying the API it’s showing some kind of error.

Here is my Github Repo Link. Kindly let me know if I need to add or delete anything.
https://github.com/Sarwagya123/Chest_XRay_Analysis_API/tree/main

The log has been attached below -

model = pickle.load(open('better model.pkl','rb')) Jul 6 02:28:26 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/keras/saving/pickle_utils.py", line 48, in deserialize_model_from_bytecode Jul 6 02:28:26 PM raise e Jul 6 02:28:26 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/keras/saving/pickle_utils.py", line 46, in deserialize_model_from_bytecode Jul 6 02:28:26 PM model = saving_lib.load_model(filepath) Jul 6 02:28:26 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/keras/saving/experimental/saving_lib.py", line 196, in load_model Jul 6 02:28:26 PM raise e Jul 6 02:28:26 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/keras/saving/experimental/saving_lib.py", line 184, in load_model Jul 6 02:28:26 PM h5_file = h5py.File(tf.io.gfile.join(temp_path, _VARS_FNAME), "r") Jul 6 02:28:26 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/h5py/_hl/files.py", line 567, in __init__ Jul 6 02:28:26 PM fid = make_fid(name, mode, userblock_size, fapl, fcpl, swmr=swmr) Jul 6 02:28:26 PM File "/opt/render/project/src/.venv/lib/python3.7/site-packages/h5py/_hl/files.py", line 231, in make_fid Jul 6 02:28:26 PM fid = h5f.open(name, flags, fapl=fapl) Jul 6 02:28:26 PM File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper Jul 6 02:28:26 PM File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper Jul 6 02:28:26 PM File "h5py/h5f.pyx", line 106, in h5py.h5f.open Jul 6 02:28:26 PM FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = '/tmp/tmplfvl6zqq/variables.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

Hey,

Your code is searching for a file in the “/tmp” folder, but it appears that the file does not exist. I’m uncertain whether it should be located at the root of your repository or the root of the filesystem. However, in either case, the file is not present during the build process. To resolve this, please ensure that the necessary files are placed in the correct location before deployment.

Furthermore, it seems that you are deploying and/or utilizing an ML model. It’s important to note that such applications typically require a paid instance with higher CPU and RAM resources allocated. These resources are crucial for the efficient operation of ML models. Therefore, it is recommended to consider using a paid instance to adequately provision the required CPU and RAM for optimal performance.

Jérémy.
Render Support, UTC+3

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.