[IGNORE THIS] Weird problem when feed pos_weight to BCEWithLogitsLoss


(Stoneyang) #1

Hi, there:

I am training a multilabel annotation predictor, with 50 labels for each image.

In the first try, I just employ BCEWithLogitsLoss without any extra arguments:

criterion = nn.BCEWithLogitsLoss().cuda()

and it works fine. After this, I wanna feed some weight term for positive samples, just like the way described in the official docs, with a torch.Tensor with the size of 50. But I received the following error:

TypeError: __init__() got an unexpected keyword argument 'pos_weight'

Could anyone give some advice? Thanks in advance!

I used a copy of pytorch 0.4.0, on a 64-bit linux machine.


(Stoneyang) #2

From the official documents, it is said:

  • pos_weight – a weight of positive examples. Must be a vector with length equal to the number of classes.

So, I’ve no idea what’s wrong with my code…


(Stoneyang) #3

This problem is because there’s no pos_weight argument in BCEWithLogitsLoss in 0.4.0 … SORRY for the inconvenience.


(rookie po) #5

Thanks for your answer !

But,how to add pos_weight to BceWithLogitsLoss in the new version?

I try to use the method to solve some data-imbalance problems.

Thanks a lot !