I am using resnet18 with BCEWithLogitsLoss()
and i am encoding my labels using y_onehot = nn.functional.one_hot(labels, num_classes=3) y_onehot = y_onehot.float()
Which is I think not true for multi label data.
How should I encode my labels to get multi labels
One workaround I use for multi-label classification is to sum the one-hot encoding along the row dimension.
For example, let’s assume there are 5 possible labels in a dataset and each item can have some subset of these labels (including all 5 labels). The code to one-hot encode an item’s labels would look like this: