在对网络进行修改时,加了一个函数supervisor(),然后运行发现出现了RuntimeError: expected device cuda:0 and dtype Float but got device cpu and dtype Float 的错误
在网上搜了很多的解决方法,有说降低Torch版本的,但对我的代码并不适用,后来发现,是因为网络使用的是gpu,而supervisor()函数中的:
branch_1 = x * mask
使用的是cpu,将其改为使用gpu即可:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
x = x.to(device)
mask = mask.to(device)
branch_1 = x * mask
再运行就成功了!
版权声明:本文为weixin_43786241原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。