Test your split data function not printing expected output

My function is only printing out:

Original cat’s directory has 12500 images
Original dog’s directory has 12500 images

There are 0 images of cats for training
There are 0 images of dogs for training
There are 0 images of cats for validation
There are 0 images of dogs for validation

instead of the expected output.

1 Like

send me your code in a private message

I’ve tried to send you code, I don’t know if you got my message.

Hello @Waffles ,

Is your problem solved?
If not yet solved, then let me know.

With regards,
Nilosree Sengupta

Hello @Waffles ,

Thanks for your response! I have seen your code snippet. I will be explaining here in detail and hope this will clear all your doubts.

For split function, you have directly written directories without defining anything before like this :

TRAINING_DIR = train_dir
VALIDATION_DIR = validation_dir

For which you were getting 0 images.
You need to define the things at first, step by step.

I would suggest you to go through the hint .

  1. It’s given in the hint :
    All images should be checked before the copy, so if they have a zero file length, they will be omitted from the copying process. If this is the case then your function should print out a message such as "filename is zero length, so ignoring.". You should perform this check before the split so that only non-zero images are considered when doing the actual split.
    Hence you need to write a condition to check if file size is greater than 0 and accept only the ones >0.

  2. It’s given in the hint : For example, if SOURCE_DIR is PetImages/Cat, and SPLIT_SIZE is .9 then 90% of the images in PetImages/Cat will be copied to the TRAINING_DIR directory and 10% of the images will be copied to the VALIDATION_DIR directory.
    So you have to Divide the file size into 2 parts- Test data size and train data size, which you can get using the split size like the above.

  3. Then group data in 2 sets.

  4. Then finally write code for the directory path for the training set and test set

Note : You need to do the above, using the given Hints below:

os.listdir(DIRECTORY) returns a list with the contents of that directory.
os.path.getsize(PATH) returns the size of the file
copyfile(source, destination) copies a file from source to destination
random.sample(list, len(list)) shuffles a list

Hope this helps.

With regards,
Nilosree Sengupta

I am getting error for some file not found FileNotFoundError: [Errno 2] No such file or directory: '/tmp/PetImages/Cat11956.jpg'

Hello @jay_mangi ,

Welcome to the community!!

It seem you are getting an error different from the error discussed under this topic. Kindly create a separate topic.Then, we mentors will surely help you.
To learn to more about community check this community guide.

With regards,
Nilosree Sengupta