What is going on? I am using Python to fetch a directory with os but it's not working
Question:
I am creating a decision tree and I give it a picture of either a cat or dog and it will decide whether it can detect if it is a cat or dog. I created a directory in my project called ‘Images’ and put a picture of a dog in it. Yet os cannot find the directory. I have tried many different types of ways to fetch the directory but it hasn’t worked.
Answers:
It looks like you’ve messed up your directory structure in the script:
- On line 19 you append a category name to
Images
folder;
- After that, you’re looking for the images in
Images\Dog
and Images\Cat
(listdir
on line 20), but Cat
and Dog
folders don’t exist inside Images
.
Either create Cat
and Dog
directories inside Images
and move pictures there or change your code according to the file structure.
I am creating a decision tree and I give it a picture of either a cat or dog and it will decide whether it can detect if it is a cat or dog. I created a directory in my project called ‘Images’ and put a picture of a dog in it. Yet os cannot find the directory. I have tried many different types of ways to fetch the directory but it hasn’t worked.
It looks like you’ve messed up your directory structure in the script:
- On line 19 you append a category name to
Images
folder; - After that, you’re looking for the images in
Images\Dog
andImages\Cat
(listdir
on line 20), butCat
andDog
folders don’t exist insideImages
.
Either create Cat
and Dog
directories inside Images
and move pictures there or change your code according to the file structure.