Skip to content

Commit

Permalink
增加配置项:CPU线程数
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroi-sora committed Oct 17, 2023
1 parent 71d5bba commit 5d1d16f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions win7_x64_PaddleOCR-json/api_paddleocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
("cls", "cls"), # 方向分类
("use_angle_cls", "cls"), # 方向分类
("limit_side_len", "limit_side_len"), # 长边压缩
("cpu_threads", "cpu_threads"), # 线程数
]


Expand Down
32 changes: 32 additions & 0 deletions win7_x64_PaddleOCR-json/paddleocr_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import psutil
from i18n import trLoad, tr

trLoad("")
Expand Down Expand Up @@ -32,6 +33,31 @@ def _getlanguageList():

_LanguageList = _getlanguageList()


# 获取最佳线程数
def _getThreads():
try:
phyCore = psutil.cpu_count(logical=False) # 物理核心数
lgiCore = psutil.cpu_count(logical=True) # 逻辑核心数
if (
not isinstance(phyCore, int)
or not isinstance(lgiCore, int)
or lgiCore < phyCore
):
raise ValueError("核心数计算异常")
# 物理核数=逻辑核数,返回逻辑核数
if phyCore * 2 == lgiCore or phyCore == lgiCore:
return lgiCore
# 大小核处理器,返回大核线程数
big = lgiCore - phyCore
return big * 2
except Exception as e:
print("[Warning] 无法获取CPU核心数!", e)
return 4


_threads = _getThreads()

globalOptions = {
"title": tr("PaddleOCR(本地)"),
"type": "group",
Expand All @@ -40,6 +66,12 @@ def _getlanguageList():
"default": True,
"toolTip": tr("使用MKL-DNN数学库提高神经网络的计算速度。能大幅加快OCR识别速度,但也会增加内存占用。"),
},
"cpu_threads": {
"title": tr("线程数"),
"default": _threads,
"min": 1,
"isInt": True,
},
"ram_max": {
"title": tr("内存占用限制"),
"default": -1,
Expand Down
1 change: 1 addition & 0 deletions win7_x64_RapidOCR-json/api_rapidocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, globalArgd):
"doAngle": 0,
"mostAngle": 0,
"maxSideLen": None,
"numThread": globalArgd["numThread"],
}

def start(self, argd): # 启动引擎。返回: "" 成功,"[Error] xxx" 失败
Expand Down
32 changes: 32 additions & 0 deletions win7_x64_RapidOCR-json/rapidocr_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import psutil
from i18n import trLoad, tr

trLoad("")
Expand Down Expand Up @@ -47,9 +48,40 @@ def _getlanguageList():

_LanguageList = _getlanguageList()


# 获取最佳线程数
def _getThreads():
try:
phyCore = psutil.cpu_count(logical=False) # 物理核心数
lgiCore = psutil.cpu_count(logical=True) # 逻辑核心数
if (
not isinstance(phyCore, int)
or not isinstance(lgiCore, int)
or lgiCore < phyCore
):
raise ValueError("核心数计算异常")
# 物理核数=逻辑核数,返回逻辑核数
if phyCore * 2 == lgiCore or phyCore == lgiCore:
return lgiCore
# 大小核处理器,返回大核线程数
big = lgiCore - phyCore
return big * 2
except Exception as e:
print("[Warning] 无法获取CPU核心数!", e)
return 4


_threads = _getThreads()

globalOptions = {
"title": tr("RapidOCR(本地)"),
"type": "group",
"numThread": {
"title": tr("线程数"),
"default": _threads,
"min": 1,
"isInt": True,
},
}

localOptions = {
Expand Down

0 comments on commit 5d1d16f

Please sign in to comment.