我正在尝试运行 ONNX 模型
import onnxruntime as ort
import onnxruntime.backend
model_path = "model.onnx"
#https://microsoft.github.io/onnxruntime/
ort_sess = ort.InferenceSession(model_path)
print( ort.get_device() )
打印出来
cpu
如何让它在我的 GPU 上运行?我如何确认它正在工作?
您可能安装了CPU版本。尝试卸载onnxruntime并安装GPU版本,如
pip install onnxruntime-gpu
。
然后:
>>> import onnxruntime as ort
>>> ort.get_device()
'GPU'
get_device() 命令为您提供 onnxruntime 支持的设备。 对于 CPU 和 GPU,有不同的运行时包可用。
目前您的onnxruntime环境仅支持CPU,因为您安装了CPU版本的onnxruntime。
如果您想构建 onnxruntime 环境以供 GPU 使用,请按照简单的步骤操作。
第1步:卸载当前的onnxruntime
>> pip uninstall onnxruntime
第2步:安装GPU版本的onnxruntime环境
>>pip install onnxruntime-gpu
第3步:验证设备对onnxruntime环境的支持
>> import onnxruntime as rt
>> rt.get_device()
'GPU'
第 4 步:如果您仍然遇到 任何问题,请检查您的 cuda 和 CuDNN 版本,它们必须彼此兼容。 请参考这个linkhere了解cuda和CuDNN之间的版本兼容性。
你的onnxruntime-gpu版本应该与你的cuda和cudnn版本相匹配,你可以从官方网站查看它们的关系: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html