How ImageDataBunch.from_list() knows which label corresponds to which file?

I read the docs but wasn’t immediately apparent. I guess I’m not that good at python either, so source code didn’t help much. I’m guessing it matches the labels with the passed fn_paths in the stored order though would like confirmation.

You are right. The match is as per the stored order.
From the docs

pass in a list of labels that correspond to each of the filenames in fnames

Also from the source code

fname2label = {f:l for (f,l) in zip(fnames, labels)}

So, this is a one-to-one mapping between fnames and labels.

1 Like