赞
踩
如果是类的话,就一定要实例化才能用:
class X():
def __init__(self):
super(X, self).__init__()
DEVICE = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
X = X().to(DEVICE)
如果没有实例化的话就会报错:AttributeError: 'torch.device' object has no attribute '_apply'
如果是数据的话就可以直接用:
img = img.to(DEVICE)
(此博客仅为了记录自己踩坑过程)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。