How to do multilabel classification with some data assign to NaN label

Fastai is so cool dealing with multilabel classification! But I met such a problem that in my data set, every image might be assigned to {0,1,…8} labels, for example: no animal, Animal A, Animal B and so on. The label is shown in a csv file, and when one is assigned to 0 label, the corresponding position says “NaN”. Just as bellows:

Image,Label
1.jpg,Animal A Animal B
2.jpg,NaN
3.jpg,Animal C

I found I could not establish the dataloader by using the method ImageDataloader.from_df, which throws errors when the length of the label is 0. I do not want to set “NaN” into the ninth class, for I found there will be strange prediction as “NaN Animal A” if I do so.(i.e. NaN must be exclusive from other 8 classes, but other 8 classes could mix up.)

Can anybody help me with the this multilabel classification problem including NaN labels? Thank you very much!

Hi there,

going with Lesson 3 - Multi-Label Classification | walkwithfastai
I would guess that replacing NaN with “” (empty string) might work quite well, would it not?

Too bad. The same error message with empty string label occured as “NaN” label. Actually “df = pd.read_csv” will get the same df, and “ImageDataLoaders.from_df” will still met label with length 0.