RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 ‘target‘
一般有三点错误
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
1、模型是否放到了CUDA上
model = model.to(device)
或 model = model.cuda()
2、输入数据是否放到了CUDA上
data = data.to(device)
或 data = data.cuda()
3、模型内部新建的张量是否放到了CUDA上 p = torch.tensor([1]).to(device)
或 p = torch.tensor([1]).cuda()
还没有评论,来说两句吧...