解决:RuntimeError: expected device cuda:0 and dtype Float but got device cpu and dtype Float

    在对网络进行修改时,加了一个函数supervisor(),然后运行发现出现了RuntimeError: expected device cuda:0 and dtype Float but got device cpu and dtype Float 的错误
解决:RuntimeError: expected device cuda:0 and dtype Float but got device cpu and dtype Float_第1张图片
    在网上搜了很多的解决方法,有说降低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

    再运行就成功了!

你可能感兴趣的:(疑难杂症,深度学习,bug)