FileNotFoundError: [Errno 2] No such file or directory: 'data/images/00018.png'

Hey! I am trying to execute a github repo LOHO for HairStyle Transfer.
But its getting pretty problematic.
This is the link to my colab file : Google Colaboratory

This is the repo that I am trying to execute : GitHub - dukebw/LOHO: Demo code for "LOHO: Latent Optimization of Hairstyles via Orthogonalization".

Error :

[7]
!python /content/LOHO/loho.py
!python /content/LOHO/loho.py
Traceback (most recent call last):
File “/content/LOHO/loho.py”, line 99, in
image_files[‘I_1_path’], image_files[‘M_1_path’], size=resize, normalize=1
File “/content/LOHO/datasets/ffhq.py”, line 77, in process_image
img = Image.open(img_path).convert(“RGB”)
File “/usr/local/lib/python3.7/site-packages/PIL/Image.py”, line 2912, in open
fp = builtins.open(filename, “rb”)
FileNotFoundError: [Errno 2] No such file or directory: ‘data/images/00018.png’

Please help , Thank you

Hi Saakshi,

You are getting this error:

FileNotFoundError: [Errno 2] No such file or directory: 'data/images/00018.png'

Isn’t that error message clear enough? There is no such file by that
name in the current directory. Either the file is misspelled or missing,
or one of the directories is misspelled or missing. Or your working
directory is not where you think it is, and you are not in the directory
you expected.

If you used os.chdir to change working directories, that could be the
problem.

Check that you are executing the code from the correct directory, on the
correct machine. Check that you haven’t misspelled the file name.
Remember that on Linux, file names are case-sensitive: 00018.png is not
the same as 00018.PNG.

Check that you are running under the correct user with the correct
permissions to see inside the directories – sometimes, if you don’t
have correct permissions, you might get “file not found”.

Do you need help with these?

I somehow manage to get the path right.
But now I am getting this "Runtime Error"

Setting up Perceptual loss…
Loading model from: /content/LOHO/networks/lpips/weights/v0.1/vgg.pth
…[net-lin [vgg]] initialized
…Done
Setting up Perceptual loss…
Loading model from: /content/LOHO/networks/lpips/weights/v0.1/vgg.pth
…[net-lin [vgg]] initialized
…Done
Constructing DeepLabv3+ model…
Number of classes: 20
Output stride: 16
Number of Input Channels: 3
Traceback (most recent call last):
File “/content/LOHO/loho.py”, line 180, in
state_dict = torch.load(graphonomy_model_path)
File “/usr/local/lib/python3.7/site-packages/torch/serialization.py”, line 593, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File “/usr/local/lib/python3.7/site-packages/torch/serialization.py”, line 779, in _legacy_load
deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)
RuntimeError: unexpected EOF, expected 1362420 more bytes. The file might be corrupted.

You “somehow” got the path right? What did you do, try random paths
until it worked? Please, if you are having problems with specific tasks,
you can ask for help.

“How do I find out the path to my file?” is a good question to ask, if
you don’t know how.

Anyway, moving on…

The error message looks fairly complete and self-explanatory to
me. It says:

RuntimeError: unexpected EOF, expected 1362420 more bytes.
The file might be corrupted.

So the file might be corrupted. Are you sure the file is good? How do
you know it is a good file? Where did you get it from?

This does not seem to be the same file as before. Earlier, your file was
a PNG image: 00018.png, if I remember correctly. Now you are unpickling
a model from a “.pth” file:

Loading model from: /content/LOHO/networks/lpips/weights/v0.1/vgg.pth

Where did this file come from? Did you create it?

One thing which would be very useful: in this script:

/content/LOHO/loho.py

line 180 says:

state_dict = torch.load(graphonomy_model_path)

but we don’t know what the graphonomy_model_path is. Can you put a line
immediately before line 180, saying:

print(graphonomy_model_path)

That will tell us what file is being used.

It looks like you are using the “torch” third-party library, and it is
trying to unpickle some file. You need to identify which file it is
using, and make sure it is the correct file. You need to do this
debugging yourself – I don’t have access to your code or data files or
the library you are using.

Maybe you are trying to use the wrong data file. Maybe the file is
corrupt. Maybe the library is buggy. It is hard to say what is
happening. Can you provide the smallest possible example that fails?

http://www.sscce.org/

That might help us to track down the cause of the fault.

This was not about the path, the images in the dataset provided were in ‘.jgp’ but i don’t know why the code was looking for '.png ’ files. Is there any way to change this like with code ? which could have been used here ??

Also, I printed the print(graphonomy_model_path)
I got the path as /content/drive/MyDrive/inference.pth

if you want to access the code here is the link : [GitHub - saakshi077/LOHO: Demo code for "LOHO: Latent Optimization of Hairstyles via Orthogonalization".]
Link to the colab file : Google Colaboratory

Hi,

I’m sorry, your question confuses me:

“”"
This was not about the path, the images in the dataset provided were in
‘.jgp’ but i don’t know why the code was looking for '.png ’ files. Is
there any way to change this like with code ? which could have been used
here ??
“”"

You said you fixed it. So you have already changed it with code. Or
maybe I don’t understand what you have done, or your question.

It is hard to help you when I don’t understand your questions.

You printed the graphonomy_model_path, thank you, and got:

/content/drive/MyDrive/inference.pth

Who provided that file? Your program is reporting that the file is
corrupt. Is it possible that it is corrupt, or that you are using the
wrong file?

If you are on a Linux system, it might help to run:

file /content/drive/MyDrive/inference.pth

and see what sort of file it is.