Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSError: Unable to open file (unable to open file)

I am trying to load a pre_trained model named "tr_model.h5" for my assignment but I get the following error:

Traceback (most recent call last):
 File "Trigger_Project.py", line 84, in <module>
model = load_model(filename)
 File "Trigger_Project.py", line 84, in <module>
model = load_model(filename)
 File "/home/neeraj/anaconda3/lib/python3.6/site-packages/h5py/_hl/files.py", line 99, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper

File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper

File "h5py/h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (unable to open file: name = 'tr_model.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

I have made sure that the file is present. I don't why it is showing os error. I am using linux 18.04 and all the required libraries are upgraded. Any help is much appreciated.

like image 684
Neeraj Avatar asked Jul 30 '18 12:07

Neeraj


2 Answers

I encounter the same issue as I posted in my question:

h5py.File(path) doesn't recognize folder path

My initial reasoning is that h5py.File(path) doesn't handle the standard subfolder path as its argument, e.g. load_model("neunet.h5") has no issue, but load_model("subfolder/neunet.h5") will give the same error.

In a nutshell, my solution is to simply put whatever .h5 files into the working home folder for in my jupyter notebook, which is the place you create the .ipynb file. You could use print(os.getcwd()) in jupyter notebook to see where is your current working directory.

like image 119
Jason Avatar answered Oct 10 '22 17:10

Jason


I had the same issue when setting the path for training checkpoints using tensorflow.keras.callbacks.ModelCheckpoint I had set my path to:

path = os.path.join(subdir,filename)

using an f string solved the problem:

path = f'{subdir}/{filename}'

So I would also check how you are importing the load_model, try tensorflow.keras.models instead of only keras.models

like image 26
Santiago Noacco Avatar answered Oct 10 '22 18:10

Santiago Noacco