i'm trying to practice transfer learning myself.
I'm trying to count the number of each cat and dog files (each 12500 pictures for cat and dog with the total of 25000 pictures).
Here is my code.Code
And here is my path for the picture folderenter image description here.
I thought this was a simple code, but still couldn't figure out why i keep getting (0,0) in my coding (supposed to be (12500 cat files,12500 dog files)):(.
Use os.path.join()
inside glob.glob()
. Also, if all your images are of a particular extension (say, jpg), you could replace '*.*'
with '*.jpg*'
for example.
import os, glob
files = glob.glob(os.path.join(path,'train/*.*'))
As a matter of fact, you might as well just do the following using os
library alone, since you are not selecting any particular file extension type.
import os
files = os.listdir(os.path.join(path,'train'))
The method os.path.join()
here helps you join multiple folders together to create a path. This will work whether you are on a Windows/Mac/Linux system. But, for windows the path-separator is \
and for Mac/Linux it is /
. So, not using os.path.join()
could create an un-resolvable path for the OS. I would use glob.glob
when I am interested in getting some specific types (extensions) of files. But glob.glob(path)
requires a valid path to work with. In my solution, os.path.join()
is creating that path from the path components and feeding it into glob.glob()
.
For more clarity, I suggest you see documentation for os.path.join
and glob.glob
.
Also, see pathlib
module for path manipulation as an alternative to os.path.join()
.