Category list to one-hot encoding

I have a dataset in Imagenet format where the images are stored in folders based on the category name. I want to build a multiclass classifier so that I can use Sigmoid loss function instead of Softmax for the purpose of being able to detect missing classes.
So I load the data using:
But I would like to have my labels as one hot encoded MultiCategoryList and what I get is a CategoryList which I can’t use with torch.nn.BCEWithLogitsLoss.
How can I easily make this transformation?

Assuming your folder names don’t have multiple labels you need to extract, passing MultiCategoryList to the label_cls parameter of label_from_folder should do the trick.

Otherwise you will probably need to use label_from_func or label_from_re to extract the labels from the folder names. label_from_folder calls label_from_func so you can look at it as an example if needed.