2021-11-08RuntimeError: Expected object of device type cuda but got device type cpu for argument #3

在尝试运行代码时遇到了RuntimeError,错误信息显示期望设备类型为cuda,但实际得到的是cpu。问题出在权重(weight)位于CPU上。通过检查并调整代码,将weight移动到cuda设备上,或者避免直接使用weight,可以解决此问题。
摘要由CSDN通过智能技术生成

报错RuntimeError: Expected object of device type cuda but got device type cpu for argument #3 'weight' in call to _thnn_nll_loss_forward


先说启发:要仔细看报错啊,这个报错是weight,而晚上都是#2等的报错

报错

RuntimeError: Expected object of device type cuda but got device type cpu for argument #3 ‘weight’ in call to _thnn_nll_loss_forward

思路

简单来说,就是weight放到了cpu上面

修改前

criterion = torch.nn.CrossEntropyLoss(weight=torch.tensor([1,7],</
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值