ptrblck:

nn.BCEWithLogits


When I used nn.BCEWithLogitsLoss() I can’t  backward loss and I have this error
RuntimeError                              Traceback (most recent call last)
 in ()
44       #avg_accuracy = train_accuracy / len(train_loader)
45       accuracy_train=train_accuracy+(correct_train/total_train_c)
—> 46       loss.backward(retain_graph=True)
47
48         ### UPDATE MODEL PARAMETERS
1 frames
/usr/local/lib/python3.7/dist-packages/torch/autograd/init.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables, inputs)
147     Variable.execution_engine.run_backward(
148         tensors, grad_tensors, retain_graph, create_graph, inputs,
 → 149         allow_unreachable=True, accumulate_grad=True)  # allow_unreachable flag
150
151
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.DoubleTensor [4, 6, 32, 32]] is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

image1366×768 118 KB

masks1 torch.Size([4, 6, 32, 32])
logits_masks torch.Size([4, 6, 32, 32]) "output "
criterion2 = nn.BCEWithLogitsLoss()