【发布时间】:2021-06-18 23:00:47
【问题描述】:
无法弄清楚问题所在。即使我将下载指向 cpu,torch 也会尝试使用 cuda 工作:
model = nn.Sequential(
nn.Conv2d(3,16,5),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(16,16,5),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(16,32,5),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(32,64,5),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(64,128,5),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Flatten(),
torch.nn.Linear(1152, 256),
torch.nn.ELU(), torch.nn.Linear(256,4)
)
model.load_state_dict(torch.load('bbox.pth',map_location=torch.device('cpu')))
ds_trans = transforms.Compose([transforms.ToTensor(),normalize,transforms.Resize((224,224))])
batch = ds_trans(img).unsqueeze(0)
ans = model(batch)
运行结果
AssertionError: Torch not compiled with CUDA enabled
模型是在 GPU 上学习的,GPU 推理运行良好,但我需要在另一台电脑上进行 cpu 推理。
【问题讨论】: