Solved by ptrblck in post #2 
              
              
                nn.BCEWithLogitsLoss should work, if the model output and target have the same shape. 
Could you print the shape of both inputs again and check, where the size of 2 is coming from?