Fnames and Labels

fnames = np.array([f'train/{f}' for f in sorted(os.listdir(f'{PATH}train'))])

labels = np.array([(0 if 'cat' in fname else 1) for fname in fnames])

Can someone please explain what these two lines are doing? It is from the code for the Image Classifier from the first lesson.

Thank You

-the first line contains a list comprehension ([…]) that reads and sorts all files in the directory train
-the second uses the file name to build an array with labels the is o for cat an 1 for dog => this is the classes that the images will be classified against

Takes time to get used to fastai’s very compressed way of writing code but you will get used to it and appreciate i after many hours of head scratching :slight_smile:

Thanks a lot @Kaspar.
Although it’s a very compressed way to write code, I love the fact that once I perfect it I will be able to write code lightning fast.
Can you, if you don’t mind please elaborate on ‘directory train’?
Thank you again.

the first line reads and sorts all of the files Inside of the directory called “train”.

Oh that’s it, thanm you @eof

it would be a directory in the folder with your data, fx if you have downloaded the dataset cifar10

Thanks for the prompt reply:)