FileNotFoundError: [Errno 2] No such file or directory: '/tmp/cats-v-dogs/training/cats/4431.jpg'

Hello. I checked all the topics here but mine is little different. I’m getting this error and says “No such file or directory: ‘/tmp/cats-v-dogs/training/cats/4431.jpg’”. My questions are:

  1. Source locations are correctly provided while calling the function as well as while defining the function which is “tmp/PetImages/Cat/”. But why does this checks “cats-v-dogs/training/cats” directory to copy the files? “cats-v-dogs/training/cats” is Destination directory.

  2. Where did I go wrong in the code? Please help me.

Below is my code:

[code removed - moderator]

1 Like

Please don’t post code on a public topic. Sharing stacktrace is okay.

Click my name and message your notebook as an attachment.

1 Like

When creating training and validation directory structure in create_train_val_dirs, please pay attention to case (see Cats instead of cats and Dogs instead of dogs:

Expected Output (directory order might vary):

/tmp/cats-v-dogs/training
/tmp/cats-v-dogs/validation
/tmp/cats-v-dogs/training/cats
/tmp/cats-v-dogs/training/dogs
/tmp/cats-v-dogs/validation/cats
/tmp/cats-v-dogs/validation/dogs

Actual

/tmp/cats-v-dogs/validation
/tmp/cats-v-dogs/training
/tmp/cats-v-dogs/validation/Dogs
/tmp/cats-v-dogs/validation/Cats
/tmp/cats-v-dogs/training/Dogs
/tmp/cats-v-dogs/training/Cats
2 Likes

I have been working on this from yesterday and realizing it is a mistake of creating folders with one capital letter, is so silly of me. :sweat_smile:

Anyways, after correcting that, it worked perfectly. Thank you. :+1:

1 Like

I changed my code based on your message, but I’m still getting the same error, No such file or directory: ‘/tmp/cats-v-dogs/training/cats/’ in the test your split data function block

Based on my experience, I think it has to do with only creation of the folders. Check each and everything clearly even the small details like “case sensitive letters”, “spaces”. Or try to check source and destinated folder have been correctly set, while copying the files.

The folders names(case sensitive) and everything should be exactly like the “Expected Output”.

1 Like

YOOOOOOO!!! Thank you so much!! I finally got passed that error, I’ve been working on this project for two weeks! I was confused on what the output was supposed to be, was it suppose to look like the “expected output”, or the “actual output” in Balaji Ambresh’s message. Now I got it. For anyone having the issue where you program gives you the error saying “No such file or directory: ‘/tmp/cats-v-dogs/training/cats/" The output in the code block where it says “# Test your create_train_val_dirs function” which is right under the code block where you create your directories for training and validation, it’s supposed to print a message that shows the “expected output” If you need help creating the train and validation directories, check the link here and it will show you an example of what the code should look like. You will have to experiment to get the code right on the assignment, but once you set up everything correctly you will no longer get that error. Thank you so much for helping me Dilipraj Dasari and Balaji Ambresh!

Same, i have a problem. My code is error and i changed my code based on your massage but, still the same error.
FileNotFoundError Traceback (most recent call last)
in <cell line: 19>()
17
18 # Empty directories in case you run this cell multiple times
—> 19 if len(os.listdir(TRAINING_CATS_DIR)) > 0:
20 for file in os.scandir(TRAINING_CATS_DIR):
21 os.remove(file.path)

FileNotFoundError: [Errno 2] No such file or directory: ‘/tmp/cats-v-dogs/training/cats/’

Hi,
Did you amange to solve it? It also followed the suggest solutions. However i’m still getting the same errro.

Please click my name and message your notebook as an attachment.