You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, Im getting the error mentioned in the title. The explanation in torch.nn.functional.cross_entropy function says that we need to give either the class indexes of ground truth classes or class probabilities (which suits to this case since the ground truths are not strict 0 1 labels but predictions coming from the pretrained model). And the code implementation seems to be correct for the second case, but it gives me runtime error so I had to change it with ground truth class indexes which seem to be work well. I dont know if it would have a significant role to decrease the accuracy though. Any idea??
The text was updated successfully, but these errors were encountered:
To resolve this error, you need to ensure that the target tensor contains long integers representing the class indices. Here are a few possible solutions:
Convert the target tensor to long integers:
importtorch# Assuming your target tensor is 'target_tensor'target_tensor=target_tensor.long()
Create the target tensor with the correct data type:
importtorch# Assuming your target data is in 'target_data'target_tensor=torch.tensor(target_data, dtype=torch.long)
Check the data type of your target tensor:
importtorch# Assuming your target tensor is 'target_tensor'print(target_tensor.dtype)
If the data type is not torch.long, convert it accordingly.
By ensuring that the target tensor contains long integers representing the class indices, you should be able to resolve the "Expected object of scalar type Long but got scalar type Float for argument #2 'target' in call to _thnn_nll_loss_forward" error.
Hello, Im getting the error mentioned in the title. The explanation in torch.nn.functional.cross_entropy function says that we need to give either the class indexes of ground truth classes or class probabilities (which suits to this case since the ground truths are not strict 0 1 labels but predictions coming from the pretrained model). And the code implementation seems to be correct for the second case, but it gives me runtime error so I had to change it with ground truth class indexes which seem to be work well. I dont know if it would have a significant role to decrease the accuracy though. Any idea??
The text was updated successfully, but these errors were encountered: