Target value with torch.nn.MultiLabelSoftMarginLoss should be 0 or -1?

Viewed 586

I have a multi-label classification problem (A single sample can be classified as several classes at the same time).

I want to use torch.nn.MultiLabelSoftMarginLoss but I got confused with the documentation where the ground truth are written like this :

Target: (N, C)(N,C) , label targets padded by -1 ensuring same shape as the input.

Does that mean the target is in one hot form, but the zero replace with -1?

Let's say I want to classified several attributes for object detection such as : Man, Tall, Long hair.
My first image is a tall woman with long hair, does my Target become 0 1 1 or -1 1 1 ? I can't fathom why use -1 instead of 0

It's quite hard to find example in internet since a lot of people mistook multi-label task as multiple class classification and keep using BCELoss.

1 Answers

Look closer at the doc:

enter image description here

The targets are expected to be {0, 1} and not -1.
I'm not sure what this -1 is doing, it might be for "ignore", but you are correct that the doc there is not very clear.

There is an open issue on pytorch's github about this. Feel free to contribute.

Related