OK, I solved the issue and found out what was going on. I will post here incase anyone follows the tutorial (Packt Publishing “Deep Learning with PyTorch”- Ch.3 “Training a Dog & Cat Classifier”):
Per this stack overflow post,https://stackoverflow.com/questions/28250993/errno13-permission-denied-in-documents-folder, I found that using “copy” instead of “copyfile” worked:
I have already found alot of errors in this PyTorch book (Deep Learning with PyTorch), and it really makes following the tutorials difficult, especially when you are learning Machine Learning via PyTorch and following the tutorials in the book and even the tutorials have erroneous code.
Anyway, after fixing that, I still had an issue with this line of code:
I basically noticed after using some “print” statements to debug and see what variables/strings path, folder and image held, that it was double-cocantenating the directories thus my images were not being copied to the correct corresponding folders (i.e. the whole point of this code was to iterate thru a glob of 25000 images and pick out 2000 images at random to create a validation set. The images were string split between cat and dog and were to be subdivided into “cat” and “dog” folders corresponding to what the image was).
So basically it was concatenating something like:
So I was able to utilize os.path.basename such as the code below to properly extract the pieces of the directory/file name I wanted to properly copy and assign the cat & dog images to their correct corresponding folders for my validation set:
for i in shuffle[:2000]:
shutil.copy(files[i],‘dogsandcats/valid’) # copies images into “valid” folder
folder = os.path.basename(files[i].split(’/’)[-1].split(’.’)) # had to use os.path.basename to extract only folder name
#print (“The folder name is: %s” % folder) # used to debug to actual see what the image name was
image = os.path.basename(files[i].split(’/’)[-1]) # had to use os.path.basename to extract only image name
#print (“The image name is: %s” % image) # used to debug to actual see what the image name was
#print (“The path name is: %s” % path)
I do appreciate the quick replies and help from peoples on these forums, thanks again and hopefully this helps anyone following the similar tutorial and loading their data/creating a validation dataset for the very-popular and basic binary image classifier of cats and dogs.