This the function I changed for option 2:
def read_dirs(path, folder):
labels, filenames, all_labels = [], [], []
full_path = os.path.join(path, folder)
for label in sorted(os.listdir(full_path)):
all_labels.append(label)
for fname in os.listdir(os.path.join(full_path, label)):
if fname.endswith('.jpg'):
filenames.append(os.path.join(folder, label, fname))
labels.append(label)
return filenames, labels, all_labels
The additional if statement simply skips files that don’t end with “.jpg”. There are probably better ways to do this.