Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileNotFoundError: Caught FileNotFoundError in DataLoader worker process 0. #9

Open
Swagzzy4 opened this issue Aug 29, 2021 · 3 comments

Comments

@Swagzzy4
Copy link

when i run the train.py with mit.yml ,here is the error:
Traceback (most recent call last):
File "train.py", line 233, in
main()
File "train.py", line 100, in main
train(epoch, image_extractor, model, trainloader, optimizer, writer)
File "train.py", line 122, in train_normal
for idx, data in tqdm(enumerate(trainloader), total=len(trainloader), desc = 'Training'):
File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/tqdm/std.py", line 1166, in iter
for obj in iterable:
File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 435, in next
data = self._next_data()
File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1085, in _next_data
return self._process_data(data)
File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/dataloader.py", line 1111, in _process_data
data.reraise()
File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/_utils.py", line 428, in reraise
raise self.exc_type(msg)
FileNotFoundError: Caught FileNotFoundError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/_utils/worker.py", line 198, in _worker_loop
data = fetcher.fetch(index)
File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/idea/zzy/czsl/data/dataset.py", line 405, in getitem
img = self.loader(image)
File "/home/idea/zzy/czsl/data/dataset.py", line 25, in call
img = Image.open(ospj(self.root_dir,img)).convert('RGB') #We don't want alpha
File "/home/idea/anaconda3/envs/czsl/lib/python3.8/site-packages/PIL/Image.py", line 2904, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'DATA_ROOT/mit-states/images/ripe_coffee/IMG_3474.jpg'

but when I run with the utzappos dataset, there are no errors!
I have not idea how to fix this error. IMG_3474.jpg is really an existing file in "DATA_ROOT/mit-states/images/ripe_coffee". How can I fix that error

@mancinimassimiliano
Copy link
Collaborator

Hello @Swagzzy4 ,

Mmm, this is weird. I assume you have here https://github.com/ExplainableML/czsl/blob/main/flags.py#L3 DATA_ROOT= "DATA_ROOT" or something similar. Is this the case?

In case it is, could you try to replace it with:
DATA_ROOT="ABS_PATH"
where ABS_PATH is the absolute path of your root folder. It might not solve the issue, but I would like to understand if it is linked to absolute vs relative paths.

@gulzainali98
Copy link

gulzainali98 commented Dec 3, 2021

I have noticed downloaded name of reps in downloaded datasets are different, they do not include "_" in their names rather include a space i.e "ripe_coffee" directory in my downloaded mit-states dataset is "ripe coffee". If you are running compcos configuration then problem for me was fixed by following changes.
in data/dataset.py replace https://github.com/ExplainableML/czsl/blob/main/data/dataset.py#L403 with the following code.

try:
  img = self.activations[image]
except Exception as e:
  if "_" in image.split("/")[0]:
    image=image.split("/")[0].replace("_"," ")+"/"+image.split("/")[1]
    img = self.activations[image]

However if you are running cge configuration, problem for me was fixed by changing the call function at line https://github.com/ExplainableML/czsl/blob/main/data/dataset.py#L24 by following function.

def __call__(self, img):
        try:
            img_pix = Image.open(ospj(self.root_dir,img)).convert('RGB') #We don't want alpha
        except Exception as e:
            if "_" in img.split("/")[0]:
                img=img.split("/")[0].replace("_"," ")+"/"+img.split("/")[1]
                img_pix = Image.open(ospj(self.root_dir,img)).convert('RGB') #We don't want alpha
        return img_pix

@mancinimassimiliano
Copy link
Collaborator

Thank you @gulzainali98 for providing a fix for this issue. We will inspect it and integrate your fix into the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants