[英]How load torch model for cpu inference
Can't figure out what the problem is.无法弄清楚问题是什么。 Even if I point the download to cpu, torch tries to use cuda to work:
即使我将下载指向 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)
result of run运行结果
AssertionError: Torch not compiled with CUDA enabled
Model was learned on GPU, and GPU inference is working well, but I need cpu inference on another pc. Model 是在 GPU 上学习的,GPU 推理运行良好,但我需要在另一台电脑上进行 cpu 推理。
Try to Reinstall the pytorch with torch,torchvision尝试用torchvision重新安装pytorch
pip install torch===1.5.0 torchvision===0.6.0 -f https://download.pytorch.org/whl/torch_stable.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.