Pytorch: RuntimeError: result type Float can’t be cast to the desired output type Long

We Are Going To Discuss About Pytorch: RuntimeError: result type Float can’t be cast to the desired output type Long. So lets Start this Python Article.

Pytorch: RuntimeError: result type Float can’t be cast to the desired output type Long

  1. How to solve Pytorch: RuntimeError: result type Float can't be cast to the desired output type Long

    I was getting the same error doing this:
    loss_fn(output, target)
    where the output was Tensor torch.float32 and target was Tensor torch.int64. What solved this problem was calling the loss function like this:
    loss_fn(output, target.float())

  2. Pytorch: RuntimeError: result type Float can't be cast to the desired output type Long

    I was getting the same error doing this:
    loss_fn(output, target)
    where the output was Tensor torch.float32 and target was Tensor torch.int64. What solved this problem was calling the loss function like this:
    loss_fn(output, target.float())

Solution 1

I was getting the same error doing this:

loss_fn(output, target)

where the output was Tensor torch.float32 and target was Tensor torch.int64. What solved this problem was calling the loss function like this:

loss_fn(output, target.float())

Original Author 5ar Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment