欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Expected object of scalar type Long but got scalar type Int for argument #2 'target'

程序员文章站 2022-06-13 08:00:24
...

Exception has occurred: RuntimeError

Expected object of scalar type Long but got scalar type Int for argument #2 'target'

 

Expected object of scalar type Long but got scalar type Int for argument #2 'target'

 

方法一:
targets =torch.LongTensor(targets)
 
方法二:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
targets = targets.to(device,dtype=torch.int64)

 

相关标签: Deep Learning