I want to compute BCEWithLogitsLoss(). I am using the following code:
for epoch in range(max_epochs):
total_epoch_loss = 0
for batch_idx, (inps, tgts) in enumerate(train_loader):
tgts = tgts.reshape((-1)).to(device)
tgts = tgts.to(torch.long)
out = cln(inps)
inpOut = torch.cat((inps, out), dim=1)
fOut = util.continuous_xor_vectorized(inpOut.T, name)
loss = criterion(fOut, tgts)
total_epoch_loss += loss
optimizer.zero_grad()
loss.backward()
optimizer.step()
where fOut and tgts are both 32 x 1 sized vectors. But getting the following error message:
Traceback (most recent call last):
File "trainClassification2ndForm.py", line 52, in <module>
cln, lossess = train_classifier(train_loader, loss_fn)
File "trainClassification2ndForm.py", line 35, in train_classifier
loss = criterion(fOut, tgts)
File "/home/ravi/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/ravi/anaconda3/lib/python3.7/site-packages/torch/nn/modules/loss.py", line 632, in forward
reduction=self.reduction)
File "/home/ravi/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py", line 2582, in binary_cross_entropy_with_logits
return torch.binary_cross_entropy_with_logits(input, target, weight, pos_weight, reduction_enum)
RuntimeError: result type Double can't be cast to the desired output type Long
If I change dtype of fOut to long, then it throws following error:
Traceback (most recent call last):
File "trainClassification2ndForm.py", line 51, in <module>
cln, lossess = train_classifier(train_loader, loss_fn)
File "trainClassification2ndForm.py", line 35, in train_classifier
loss = criterion(fOut, tgts)
File "/home/ravi/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/ravi/anaconda3/lib/python3.7/site-packages/torch/nn/modules/loss.py", line 632, in forward
reduction=self.reduction)
File "/home/ravi/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py", line 2582, in binary_cross_entropy_with_logits
return torch.binary_cross_entropy_with_logits(input, target, weight, pos_weight, reduction_enum)
RuntimeError: exp_vml_cpu not implemented for 'Long'
I am unable to find out the mistake. Can anyone please help here?
Thanks!