I have a folder structure listed like the following
MA/valid/wrist/pa/positive/image2.png
Basically, for each wrist there are multiple pa, and for each pa there is a positive or negative study, and for each study there are up to 3 images in png format.
I have written a code below, but it only goes down to the pa level, it does not load my image files. Any help with loading my image files will be appreciated.
def load(Pic_Dir,Imsize):
data = []
dirs = next(os.walk(Pic_Dir))[1]
for dir_name in dirs:
files = next(os.walk(os.path.join(Pic_Dir, dir_name)))[2]
print("load [", len(files), "] files from [",dir_name,"] " )
for i in range(len(files)):
image_name = files[i]
image_path = os.path.join(Pic_Dir, dir_name, image_name)
label = dir_name
img = cv2.imread(image_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (Imsize, Imsize))
data.append([np.array(img), label])
return
The function is called with the following line:
data=load("/Users/bond/MA/train/XR_WRIST",244)