[英]How do you run a ONNX model on a GPU?
I'm trying to run an ONNX model我正在尝试运行 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() )
This prints out这打印出来
cpu
How can I make it run on my GPU?如何让它在我的 GPU 上运行? How can I confirm it's working?我如何确认它正在工作?
You probably installed the CPU version.您可能安装了 CPU 版本。 Try uninstalling onnxruntime and install GPU version, like pip install onnxruntime-gpu
.尝试卸载 onnxruntime 并安装 GPU 版本,例如pip install onnxruntime-gpu
。
Then:然后:
>>> import onnxruntime as ort
>>> ort.get_device()
'GPU'
get_device() command gives you the supported device to the onnxruntime. get_device() 命令为您提供 onnxruntime 支持的设备。 For CPU and GPU there is different runtime packages are available.对于 CPU 和 GPU,有不同的运行时包可用。
Currently your onnxruntime environment support only CPU because you have installed CPU version of onnxruntime.目前您的 onnxruntime 环境仅支持 CPU,因为您安装了 onnxruntime 的 CPU 版本。
If you want to build onnxruntime environment for GPU use following simple steps.如果您想为 GPU 构建 onnxruntime 环境,请使用以下简单步骤。
Step 1: uninstall your current onnxruntime第 1 步:卸载您当前的 onnxruntime
>> pip uninstall onnxruntime
Step 2: install GPU version of onnxruntime environment第二步:安装GPU版onnxruntime环境
>>pip install onnxruntime-gpu
Step 3: Verify the device support for onnxruntime environment步骤 3:验证设备对 onnxruntime 环境的支持
>> import onnxruntime as rt
>> rt.get_device()
'GPU'
Step 4: If you encounter any issue please check with your cuda and CuDNN versions, that must be compatible to each other.第 4 步:如果您遇到任何问题,请检查您的 cuda 和 CuDNN 版本,它们必须相互兼容。 Please refer this link here to understand about the version compatibility between cuda and CuDNN.请参考以下链接点击这里了解有关CUDA和CuDNN之间的版本兼容性。
您的 onnxruntime-gpu 版本应该与您的 cuda 和 cudnn 版本匹配,您可以从官方网站查看它们的关系: https ://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.