π Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
fix(config): Remove the default installation onnxruntime-directml restriction on Windows.
SWHL7a731483a5ed
diff --git a/python/rapidocr_onnxruntime/utils.py b/python/rapidocr_onnxruntime/utils.pyindex 3a345f4..7030d7f 100644--- a/python/rapidocr_onnxruntime/utils.py+++ b/python/rapidocr_onnxruntime/utils.py@@ -2,15 +2,16 @@# @Author: SWHL# @Contact: [email protected]import argparse+import importlibimport mathimport os+import platformimport randomimport tracebackimport warningsfrom io import BytesIOfrom pathlib import Pathfrom typing import Dict, List, Optional, Tuple, Union-import platformimport cv2import numpy as np@@ -67,10 +68,9 @@ class OrtInferSession:cpu_provider_opts = {"arena_extend_strategy": "kSameAsRequested",}-EP_list = [(CPU_EP, cpu_provider_opts)]- use_cuda = (+ self.use_cuda = (self.cfg_use_cuda and get_device() == "GPU" and CUDA_EP in had_providers)cuda_provider_opts = {@@ -79,21 +79,39 @@ class OrtInferSession:"cudnn_conv_algo_search": "EXHAUSTIVE","do_copy_in_default_stream": True,}+# check windows 10 or above- # use_directml = platform and DIRECTML_EP in had_providers and self.cfg_use_cuda("use_dml")- use_directml = platform.system() == "Windows" and platform.release().split(".")[0] >= "10" and DIRECTML_EP in had_providers and self.cfg_use_dml- if use_cuda:+ self.use_directml = (+ platform.system() == "Windows"+ and platform.release().split(".")[0] >= "10"+ and DIRECTML_EP in had_providers+ and self.cfg_use_dml+ )+ if self.use_cuda:EP_list.insert(0, (CUDA_EP, cuda_provider_opts))- elif use_directml:- print("Windows 10 or above detected, try to use DirectML as primary provider")- directml_options = cuda_provider_opts if use_cuda else cpu_provider_opts+ elif self.use_directml:+ self._verfiy_dml()+ print(+ "Windows 10 or above detected, try to use DirectML as primary provider"+ )+ directml_options = (+ cuda_provider_opts if self.use_cuda else cpu_provider_opts+ )EP_list.insert(0, (DIRECTML_EP, directml_options))return EP_list+ def _verfiy_dml(self):+ try:+ importlib.import_module("onnxruntime-directml")+ except ModuleNotFoundError as exc:+ raise ModuleNotFoundError(+ "If there are other onnxruntime packages installed, please use pip uninstall onnxruntime to uninstall them first. \nThen install the package using DirectML through pip install onnxruntime-directml."+ ) from exc+def _verify_providers(self) -> None:session_providers = self.session.get_providers()-- if self.cfg_use_cuda and CUDA_EP not in session_providers:++ if self.use_cuda and session_providers[0] != CUDA_EP:warnings.warn(f"{CUDA_EP} is not avaiable for current env, the inference part is automatically shifted to be executed under {CPU_EP}.\n""Please ensure the installed onnxruntime-gpu version matches your cuda and cudnn version, "@@ -101,14 +119,12 @@ class OrtInferSession:"https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html",RuntimeWarning,)-- use_directml = platform.system() == "Windows" and platform.release().split(".")[0] >= "10" and self.cfg_use_dml- if use_directml and session_providers[0] != DIRECTML_EP:++ if self.use_directml and session_providers[0] != DIRECTML_EP:warnings.warn("DirectML is not available for the current environment, the inference part is automatically shifted to be executed under other EP.\n")-def __call__(self, input_content: np.ndarray) -> np.ndarray:input_dict = dict(zip(self.get_input_names(), [input_content]))try:diff --git a/python/requirements_ort.txt b/python/requirements_ort.txtindex 9b62944..5cc0e39 100644--- a/python/requirements_ort.txt+++ b/python/requirements_ort.txt@@ -5,6 +5,4 @@ six>=1.15.0Shapely>=1.7.1PyYAMLPillow-# install the onnxruntime-directml if on windows platform, notice that the onnxruntime-directml is conflict with onnxruntime, we can only install one of them-onnxruntime-directml;platform_system=="Windows"-onnxruntime>=1.7.0;platform_system!="Windows"\ No newline at end of file+onnxruntime>=1.7.0\ No newline at end of file