There are some issues in the code:


Variables are deprecated since PyTorch 0.4, so you can use tensors now.
Don’t call .forward, but the module directly via: model(inputs).

nn.BCELoss is used for a binary classification (or multi-label classification) and expects a sigmoid as the last non-linearity. We generally recommend to use raw logits + nn.BCEWithLogitsLoss for better numerical stability.

argmax will create an output of LongTensors, which will break the computation graph, since LongTensors cannot have gradients. It’s also not needed to call argmax on the output before passing it to the criterion.