About the usage of Cross Entropy Loss in PyTorch…
Someone could make an example illustrating how to use this loss?
I am getting this error(Dimension out of range (expected to be in range of [-1, 0], but got 1)), I am already saw the other posts about it but I didn’t understand how to use this loss yet.
input = torch.randn(4,4)
target = torch.randint(1,4,(4,))
loss = F.cross_entropy(input, target)
Please note that “input” is a 2d tensor whereas “target” is 1d tensor. The function expects first input tensor to be 2 dimensional, (N,C) and second tensor to be 1 dimensional. See [doc]
Thank you for the nice recommendation.
I have a question in regards to tuning the thresholding to favor some classes. Could you elaborate on what you mean by this and how we can achieve the tuning?