@ptrblck could you help me?
Hi everyone!
Please, someone could explain the math under the hood of Cross Entropy Loss in PyTorch?
I was performing some tests here and result of the Cross Entropy Loss in PyTorch doesn’t match with the result using the expression below:

I took some examples calculated using the expression above and executed it using the Cross Entropy Loss in PyTorch and the results were not the same.
I am trying this example here using Cross Entropy Loss from PyTorch:
probs1 = torch.tensor([[
    [
      [ 0.1, 0.3],
      [0.4, 0.5]
    ],
    [
      [0.2, 0.3],
      [0.4, 0.5]
    ],
    [
      [0.7, 0.4],
      [0.2, 0.0]
    ]
  ]])

target = torch.tensor([
    [
      [2, 2],
      [0, 1]
    ]
  ])

print(torch.sum(probs1, dim=0))
print(probs1.shape)

criterion = nn.CrossEntropyLoss()
loss = criterion(probs1, target)
loss

result -> tensor(0.9488)

Each pixel along the 3 channels corresponds to a probability distribution…there is a probability distribution for each position of the tensor…and the target has the classes for each distribution.
How can I know if this loss is beign computed correctly?
Best regards,
Matheus Santos.