Replies: 7 comments 26 replies
-
我是第一次知道 |
Beta Was this translation helpful? Give feedback.
-
这是gemini的参考回答 https://sdk.vercel.ai/s/1XYJ7spaktu3LaB35oTjG win7不太清楚,但我觉得可以fallback到其他provider之类的 按我之前其他python项目的集成经验,只需要把依赖项从onnxruntime 改到 onnxruntime-directml 这是一段参考代码 @classmethod
@time_it
def setup_model(cls, model_path: str):
provider = ['DmlExecutionProvider', 'CPUExecutionProvider']
so = ort.SessionOptions()
so.enable_mem_pattern = False
try:
if cls.ort_sess:
del cls.ort_sess
cls.ort_sess = ort.InferenceSession(
model_path, providers=provider, sess_options=so)
model_warm_up(cls.ort_sess, cls.hps)
cls.model_is_ok = True
# model_warm_up(cls.ort_sess, cls.hps)
except Exception as e:
logger.error(e)
raise e gpt总结ONNX Runtime 是一个开源的机器学习推理引擎,支持在各种平台和设备上部署训练好的模型。ONNX Runtime-DirectML 是其一个组件,利用 DirectML 库为 Windows 系统上的 ONNX 模型推理提供 GPU 加速,带来显著的性能提升和更广泛的硬件支持。 使用 DirectML 的主要优势包括:
总而言之,ONNX Runtime-DirectML 为 Windows 用户提供了高效便捷的 ONNX 模型推理解决方案,尤其适合需要 GPU 加速的机器学习任务。 |
Beta Was this translation helpful? Give feedback.
-
测试时间 2024.5.14 ONNX Runtime-DirectML patch 已经合并到主分支。 以下是复现步骤:
git clone https://github.com/RapidAI/RapidOCR.git
cd RapidOCR/python
pip install -r requirements_ort.txt
cp /path/to/testimg.png ./testimg.png
python -m rapidocr_onnxruntime.main --img ./testimg.png
hyperfine --warmup 3 "python -m rapidocr_onnxruntime.main --img ./testimg.png"
pip uninstall onnxruntime-directml
pip install onnxruntime
hyperfine --warmup 3 "python -m rapidocr_onnxruntime.main --img ./testimg.png"
(p311) D:\work\RapidOCR\python>hyperfine --warmup 3 "python -m rapidocr_onnxruntime.main --img ./testimg.png"
Benchmark 1: python -m rapidocr_onnxruntime.main --img ./testimg.png
Time (mean ± σ): 2.873 s ± 0.101 s [User: 1.798 s, System: 0.470 s]
Range (min … max): 2.725 s … 3.043 s 10 runs
(p311) D:\work\RapidOCR\python>pip uninstall onnxruntime-directml
Found existing installation: onnxruntime-directml 1.17.3
Uninstalling onnxruntime-directml-1.17.3:
Would remove:
d:\scoop\scoop\persist\mambaforge\envs\p311\lib\site-packages\onnxruntime\*
d:\scoop\scoop\persist\mambaforge\envs\p311\lib\site-packages\onnxruntime_directml-1.17.3.dist-info\*
d:\scoop\scoop\persist\mambaforge\envs\p311\scripts\onnxruntime_test.exe
Proceed (Y/n)? y
Successfully uninstalled onnxruntime-directml-1.17.3
(p311) D:\work\RapidOCR\python>pip install onnxruntime
Collecting onnxruntime
Using cached onnxruntime-1.17.3-cp311-cp311-win_amd64.whl.metadata (4.6 kB)
Requirement already satisfied: coloredlogs in d:\scoop\scoop\apps\mambaforge\current\envs\p311\lib\site-packages (from onnxruntime) (15.0.1)
Requirement already satisfied: flatbuffers in d:\scoop\scoop\apps\mambaforge\current\envs\p311\lib\site-packages (from onnxruntime) (24.3.25)
Requirement already satisfied: numpy>=1.24.2 in d:\scoop\scoop\apps\mambaforge\current\envs\p311\lib\site-packages (from onnxruntime) (1.26.4)
Requirement already satisfied: packaging in d:\scoop\scoop\apps\mambaforge\current\envs\p311\lib\site-packages (from onnxruntime) (24.0)
Requirement already satisfied: protobuf in d:\scoop\scoop\apps\mambaforge\current\envs\p311\lib\site-packages (from onnxruntime) (5.26.1)
Requirement already satisfied: sympy in d:\scoop\scoop\apps\mambaforge\current\envs\p311\lib\site-packages (from onnxruntime) (1.12)
Requirement already satisfied: humanfriendly>=9.1 in d:\scoop\scoop\apps\mambaforge\current\envs\p311\lib\site-packages (from coloredlogs->onnxruntime) (10.0)
Requirement already satisfied: mpmath>=0.19 in d:\scoop\scoop\apps\mambaforge\current\envs\p311\lib\site-packages (from sympy->onnxruntime) (1.3.0)
Requirement already satisfied: pyreadline3 in d:\scoop\scoop\apps\mambaforge\current\envs\p311\lib\site-packages (from humanfriendly>=9.1->coloredlogs->onnxruntime) (3.4.1)
Using cached onnxruntime-1.17.3-cp311-cp311-win_amd64.whl (5.6 MB)
Installing collected packages: onnxruntime
Successfully installed onnxruntime-1.17.3
(p311) D:\work\RapidOCR\python>hyperfine --warmup 3 "python -m rapidocr_onnxruntime.main --img ./testimg.png"
Benchmark 1: python -m rapidocr_onnxruntime.main --img ./testimg.png
Time (mean ± σ): 5.256 s ± 0.146 s [User: 25.242 s, System: 8.866 s]
Range (min … max): 5.081 s … 5.563 s 10 runs |
Beta Was this translation helpful? Give feedback.
-
回家用自己机子又试了下,好像还和测试图有关,自己跑的项目确实慢了。 测试图11.3.17
1.3.18
测试图21.3.17
1.3.18
|
Beta Was this translation helpful? Give feedback.
-
Per my testing (with AMD Ryzen 7 Pro 4750G, Vega 8, Windows 10 19045), the GPU is not recogized by onnxruntime-directml, and only shows CPU-DML provider. The inference time is about 40% longer than using CPU provider in onnxruntime-cpu. Uninstalling onnxruntime-directml may leave some unwanted files and mess up with onnxruntime. |
Beta Was this translation helpful? Give feedback.
-
输出: |
Beta Was this translation helpful? Give feedback.
-
RT, 提供原生gpu支持,甚至可以调用核显, 并且依赖大小比较小,其他平台可以fallback到cpu
Beta Was this translation helpful? Give feedback.
All reactions