简体   繁体   English

如何加载 Torch model 进行 CPU 推理

[英]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.

相关问题 如何加载 model 进行推理? - How to load model for inference? 运行时错误:有没有办法在 CPU 上执行 torch.load(model.pt)? - Runtimeerror: Is there a way to torch.load(model.pt) on CPU? 如何加载经过训练的 model 以推断预测数据 - How to load a trained model to inference the predicted data 如何使用除检查点以外的火炬保存加载方法将 ray rllib pytorch 整个模型导入下一轮训练和后续推理 - How can I import a ray rllib pytorch whole model into next round training and subsquent inference using torch save load method other than checkpoints 仅使用 torch.save(model) 保存后如何加载模型? - How to load model after saving only with torch.save(model)? 如何使用 torch.hub.load 加载本地 model? - How do I load a local model with torch.hub.load? 如何以.pb格式保存模型,然后将其加载以在Tensorflow中进行推理? - How to save model in .pb format and then load it for inference in Tensorflow? 请使用 torch.load 和 map_location=torch.device('cpu') 到 map 你的存储到 CPU - please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU CPU 上 Tensorflow model 服务器与 Tensorflow Z20F35E630DAF44DBFA4C3F68F5C3 相比的性能问题 - Performance issue with Tensorflow model server on CPU in comparison with Tensorflow model inference 在本地加载 Amazon Sagemaker NTM 模型以进行推理 - Load Amazon Sagemaker NTM model locally for inference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM