Hello all, thanks in advance for your time.
I am writing a custom loss function. There are 8 methods that I use in the loss function. My network is for image segmentation, and outputs logits.
the custom loss function uses:
torch.nn.Softmax()
torch.max()
torch.eq()
torch.logical_or()
torch_tensor.bool().int()
torch_tensor.sum()
torch_scaler.abs()
However when I do loss.backward(), the network says: ‘RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn’
I understand that torch.eq() will break the gradient, hence question 1 is ‘how can I circumvent this issue’
I need to count the occurrences of certain class in the torch tensor, hence Im not sure how I would avoid using torch.eq()
and secondly, does torch_tensor.bool().int() break gradient as well? If so, would switching to torch.gt(torch_logits, 1).sum() resolve the broken gradient?