有一些论文公布的代码采用了model=model.to(device)这种模式
按照我的理解,应该是和model.cuda()是一样的功能
使用cpu运算:将torch.load()函数中的map_location参数设置为torch.device('cpu')
device = torch.device('cpu')
model = TheModelClass(*args, **kwargs)
model.load_state_dict(torch.load(PATH, map_location=device))
使用GPU运算:将由GPU保存的模型加载到GPU上。确保对输入的tensors调用input = input.to(device)方法。
device = torch.device("cuda")
model = TheModelClass(*args, **kwargs)
model.load_state_dict(torch.load(PATH))
model.to(device)