How to handle unbalance data of multi-label classification?

#1

It seems that ImageDataBunch cannot set the label weight since I am doing unbalanced multi-label classification problem. Is there any way to do it?

Additionally, I found binary_cross_entropy_with_logits is the default loss function for the multi-label problem, but I don’t know how to set the pos_weight parameter, it seems to be useful for label weight, I don’t know, I tried this:

learner = create_cnn(data=data, arch=arch, 
                     loss_func=nn.BCEWithLogitsLoss(pos_weight=torch.from_numpy(my_weight)), 
                     ...
                    )

But I got an exception when I fit:

RuntimeError: TensorIterator expected type torch.DoubleTensor but got torch.cuda.FloatTensor

I changed to:

loss_func=nn.BCEWithLogitsLoss(pos_weight=torch.from_numpy(my_weight).cpu().float()), 
RuntimeError: TensorIterator expected type torch.FloatTensor but got torch.cuda.FloatTensor

So how to handle the unbalanced multi-label problem? Thanks much!

1 Like

(Thomas) #2

check my last answer here:

0 Likes