How to understand the message from TypeError?

Now I use BCELoss to train a net ,and get a TypeError:

TypeError: CudaBCECriterion_updateOutput received an invalid combination of arguments 
- got (int, torch.cuda.FloatTensor, torch.cuda.FloatTensor, 
         torch.cuda.FloatTensor, torch.cuda.FloatTensor), 
but expected (int state, torch.cuda.FloatTensor input, torch.cuda.FloatTensor target,
  torch.cuda.FloatTensor output, bool sizeAverage, [torch.cuda.FloatTensor weights or None])

It seems that the types of prediction and label are not correct,but I’m sure I make them the same data type,and from the above error message the data types also agree with the expected parameter type of function.so what’s the real message the TypeError really want to say ?


hmm this is a bit weird. Is there a code snippet I can see to reproduce this error?

The below code produce your error ‘TypeError: CudaBCECriterion_updateOutput received …’

    batch_size  = 64
    num_classes = 17
    C,H,W = 3,256,256


    inputs = torch.randn(batch_size,C,H,W)
    labels = torch.randn(batch_size,num_classes)
    in_shape = inputs.size()[1:]

    if 1:
        net = densenet121(in_shape=in_shape, num_classes=num_classes).cuda().train()

        x = Variable(inputs)
        logits, probs = net.forward(x.cuda())

        loss = nn.MultiLabelSoftMarginLoss()(logits, Variable(labels))
        loss.backward()

        print(type(net))
        print(net)
        print(probs)

The error can be corrected by

loss = nn.MultiLabelSoftMarginLoss()(logits, Variable(labels.cuda()))