Multi target is not supported!


(Kellenf) #1

I want to convert a tensorflow code into pytorch,and in tensorflow there is a function:tf.nn.sigmoid_cross_entropy_with_logits
my code is like this:

def sigmoid_cross_entropy_with_logits(output,target):
    output=F.sigmoid(output)
    loss=F.nll_loss(output,target)
    return  loss

output size:[32,252]
target size:[32,252]
And the target is One-hot Target
Now I have the error:

RuntimeError: multi-target not supported at /opt/conda/conda-bld/pytorch_1532579805626/work/ate
n/src/THCUNN/generic/ClassNLLCriterion.cu:15

Who can help me ?thanks!


#2

For a multi-label classification you could use nn.BCEWithLogitsLoss or F.sigmoid + nn.BCELoss instead of nn.NLLLoss.