Thank you very much. I just tried with:
criterion_none = torch.nn.CrossEntropyLoss(reduction=‘none’)
criterion = torch.nn.CrossEntropyLoss()
And indeed, it gave me the same loss.
loss torch.mean() tensor(1.3486, device=‘cuda:0’, grad_fn=) loss reduction tensor(1.3486, device=‘cuda:0’, grad_fn=)
I read the post with the example you gave for manual calculation of loss. I am still trying to adapt this part:
loss_weighted_manual = loss_weighted_manual.sum() / weights[target].sum()
for image segmentation. I guess I’ll figure it out.
Thank you again.