调试报错
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
截图
说明
在调试运行导师给的程序Residual Net的GunPoint程序时,出现报错,调试结果为输入与网络不符。
原因
- 输入的数据类型与网络参数的类型不符
- Input type为torch.cuda.FloatTensor(GPU数据类型), weight
type(即net.parameters)为torch.FloatTensor(CPU数据类型)
解决方案
net = mdl.ResNet()
改为↓
net = mdl.ResNet().cuda()
环境
vscode+pytorch环境(python3.6.10)