Skip to content

optim some infer yaml, readme and parallel #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: DistillationDBPostProcess
name: DBPostprocess
binary_thresh: 0.3
box_thresh: 0.6
max_candidates: 1000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: DistillationCTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
blank_at_last: False

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
2 changes: 1 addition & 1 deletion deploy/py_infer/src/configs/rec/ppocr/en_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
2 changes: 1 addition & 1 deletion deploy/py_infer/src/configs/rec/ppocr/ka_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
blank_at_last: False

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
2 changes: 1 addition & 1 deletion deploy/py_infer/src/configs/rec/ppocr/ta_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
2 changes: 1 addition & 1 deletion deploy/py_infer/src/configs/rec/ppocr/te_PP-OCRv3_rec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
postprocess:
name: CTCLabelDecode
name: RecCTCLabelDecode
use_space_char: True
use_redundant_space_char: True
blank_at_last: False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
# det
"DBPostprocess": det_postprocess.DBPostprocess,
"EASTPostprocess": det_postprocess.EASTPostprocess,
"DistillationDBPostProcess": det_postprocess.DBPostprocess,
"PSEPostprocess": det_postprocess.PSEPostprocess,
"SASTPostprocess": det_postprocess.SASTPostprocess,
"FCEPostprocess": det_postprocess.FCEPostprocess,
# rec
"RecCTCLabelDecode": rec_postprocess.RecCTCLabelDecode,
"CTCLabelDecode": rec_postprocess.RecCTCLabelDecode,
"DistillationCTCLabelDecode": rec_postprocess.RecCTCLabelDecode,
"RecAttnLabelDecode": rec_postprocess.RecAttnLabelDecode,
"ViTSTRLabelDecode": rec_postprocess.ViTSTRLabelDecode,
"AttentionLabelDecode": rec_postprocess.AttentionLabelDecode,
# cls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
sys.path.insert(0, mindocr_path)

from mindocr.postprocess import rec_postprocess # noqa
from mindocr.postprocess.rec_postprocess import RecAttnLabelDecode # noqa


# TODO: unify RecCTCLabelDecode with with trained side
Expand Down
2 changes: 1 addition & 1 deletion deploy/py_infer/src/parallel/datatype/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .message_data import ProfilingData, StopSign
from .message_data import ProfilingData, StartSign, StopSign
from .module_data import ModuleConnectDesc, ModuleDesc, ModuleInitArgs
from .process_data import ProcessData, StopData
5 changes: 5 additions & 0 deletions deploy/py_infer/src/parallel/datatype/message_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from dataclasses import dataclass


@dataclass
class StartSign:
start: bool = True


@dataclass
class StopSign:
stop: bool = True
Expand Down
3 changes: 1 addition & 2 deletions deploy/py_infer/src/parallel/datatype/process_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class ProcessData:
image_id: int = ""
frame: np.ndarray = None

original_width: int = 0
original_height: int = 0
sub_image_list: list = field(default_factory=lambda: [])
sub_image_size: int = 0
data: Union[np.ndarray, List[np.ndarray], Dict] = None
Expand All @@ -29,3 +27,4 @@ class ProcessData:
class StopData:
skip: bool = True
image_total: int = 0
exception: bool = False
15 changes: 10 additions & 5 deletions deploy/py_infer/src/parallel/framework/module_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from multiprocessing import Manager

from ...utils import log
from ..datatype import ModuleInitArgs, ProfilingData
from ..datatype import ModuleInitArgs, ProfilingData, StopData


class ModuleBase(object):
Expand All @@ -14,7 +14,6 @@ def __init__(self, args, msg_queue):
self.module_name = ""
self.without_input_queue = False
self.instance_id = 0
self.device_id = -1
self.is_stop = False
self.msg_queue = msg_queue
self.input_queue = None
Expand All @@ -36,9 +35,14 @@ def process_handler(self, stop_manager, input_queue, output_queue):
log.error(f"{self.__class__.__name__} init failed: {error}")
raise error

while not self.msg_queue.full() and stop_manager.full():
# waiting for init sign
while not self.msg_queue.full():
continue
time.sleep(0.5)

# waiting for the release of stop sign
while stop_manager.full():
continue

while True:
if stop_manager.full():
break
Expand All @@ -54,7 +58,9 @@ def call_process(self, send_data=None):
try:
self.process(send_data)
except Exception as error:
self.process(StopData(exception=True))
log.exception(f"ERROR occurred in {self.module_name} module for {send_data.image_name}: {error}.")

cost_time = time.time() - start_time
self.process_cost.value += cost_time

Expand Down Expand Up @@ -85,7 +91,6 @@ def stop(self):
profiling_data = ProfilingData(
module_name=self.module_name,
instance_id=self.instance_id,
device_id=self.device_id,
process_cost_time=self.process_cost.value,
send_cost_time=self.send_cost.value,
)
Expand Down
8 changes: 0 additions & 8 deletions deploy/py_infer/src/parallel/framework/module_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class ModuleManager:
MODULE_QUEUE_MAX_SIZE = 16

def __init__(self, msg_queue: Queue, task_queue: Queue, args):
self.device_id = 0
self.pipeline_map = defaultdict(lambda: defaultdict(ModulesInfo))
self.msg_queue = msg_queue
self.stop_manager = Queue(1)
Expand Down Expand Up @@ -116,13 +115,6 @@ def run_pipeline(self):
process.start()

def deinit_pipeline_module(self):
# wait for the stop msg
while self.stop_manager.empty():
continue

# pop the sign from shared queue
self.stop_manager.get()

# the empty() is not reliable, double check the msg queue is empty for receive the profiling data
while not self.msg_queue.empty():
self.msg_queue.get()
Expand Down
3 changes: 2 additions & 1 deletion deploy/py_infer/src/parallel/module/common/collect_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def process(self, input_data):
self.result_handle(input_data)
elif isinstance(input_data, StopData):
self.stop_handle(input_data)
if input_data.exception:
self.send_to_next_module("stop")
else:
raise ValueError("unknown input data")

Expand All @@ -111,7 +113,6 @@ def stop(self):
profiling_data = ProfilingData(
module_name=self.module_name,
instance_id=self.instance_id,
device_id=self.device_id,
process_cost_time=self.process_cost.value,
send_cost_time=self.send_cost.value,
image_total=self.image_total.value,
Expand Down
10 changes: 1 addition & 9 deletions deploy/py_infer/src/parallel/module/common/decode_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ def __init__(self, args, msg_queue):
super().__init__(args, msg_queue)
self.cost_time = 0

def decode(self, image_path):
image_src = cv_utils.img_read(image_path)
return image_src

def init_self_args(self):
super().init_self_args()

Expand All @@ -21,11 +17,7 @@ def process(self, input_data):

image_path = input_data.image_path

image_src = self.decode(image_path)
h, w = cv_utils.get_hw_of_img(image_src)

image_src = cv_utils.img_read(image_path)
input_data.frame = image_src
input_data.original_width = w
input_data.original_height = h

self.send_to_next_module(input_data)
30 changes: 19 additions & 11 deletions deploy/py_infer/src/parallel/parallel_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ..infer import SUPPORTED_TASK_BASIC_MODULE
from ..utils import log, safe_div
from .datatype import ModuleConnectDesc, ModuleDesc, StopSign
from .datatype import ModuleConnectDesc, ModuleDesc, StartSign, StopSign
from .framework import ModuleManager
from .module import MODEL_DICT

Expand All @@ -30,6 +30,7 @@ def start_pipeline(self):
self.input_queue = Queue(self.TASK_QUEUE_SIZE)
self.process = Process(target=self._build_pipeline_kernel)
self.process.start()
self.input_queue.get(block=True)

def stop_pipeline(self):
self.input_queue.put(StopSign(), block=True)
Expand Down Expand Up @@ -71,20 +72,27 @@ def _build_pipeline_kernel(self):

# waiting for task receive
while not msg_queue.full():
time.sleep(0.1)
continue

start_time = time.time()
# release all init sign
for _ in range(module_size):
msg_queue.get()

# send start sign for input queue
self.input_queue.put(StartSign())

# release the stop sign, infer start
manager.stop_manager.get(block=False)

manager.deinit_pipeline_module()
start_time = time.time()

# waiting for inference, and pop the sign from shared queue
manager.stop_manager.get(block=True)

cost_time = time.time() - start_time

manager.deinit_pipeline_module()

# collect the profiling data
profiling_data = defaultdict(lambda: [0, 0])
image_total = 0
Expand All @@ -95,13 +103,13 @@ def _build_pipeline_kernel(self):
if msg_info.module_name != -1:
image_total = msg_info.image_total

self.profiling(profiling_data, image_total)

print(
f"Number of images: {image_total}, "
f"total cost {cost_time:.2f}s, "
f"FPS: {safe_div(image_total, cost_time):.2f}"
)
if image_total > 0:
self.profiling(profiling_data, image_total)
print(
f"Number of images: {image_total}, "
f"total cost {cost_time:.2f}s, "
f"FPS: {safe_div(image_total, cost_time):.2f}"
)

msg_queue.close()
msg_queue.join_thread()
Expand Down
2 changes: 1 addition & 1 deletion docs/cn/inference/models_list_thirdparty.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MindOCR可以支持第三方模型(如PaddleOCR、MMOCR等)的推理,本
| en_pp_det_OCRv3 | DBNet | MobileNetV3 | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/ch_PP-OCRv3_det_cml.yaml) | [pp-infer](https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_det_infer.tar) | [en_PP-OCRv3_det](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/models_list_en.md) |
| ml_pp_det_OCRv3 | DBNet | MobileNetV3 | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/ch_PP-OCRv3_det_cml.yaml) | [pp-infer](https://paddleocr.bj.bcebos.com/PP-OCRv3/multilingual/Multilingual_PP-OCRv3_det_infer.tar) | [ml_PP-OCRv3_det](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/models_list_en.md) |
| en_pp_det_dbnet_resnet50vd | DBNet | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_db.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_db_v2.0_train.tar) | [DBNet](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_det_db_en.md) |
| en_pp_det_psenet_resnet50vd | PSE | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_pse.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar) | [PSE](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_overview_en.md) |
| en_pp_det_psenet_resnet50vd | PSE | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_pse.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar) | [PSE](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_ch/algorithm_det_psenet.md) |
| en_pp_det_east_resnet50vd | EAST | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_east.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_east_v2.0_train.tar) | [EAST](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_det_east_en.md) |
| en_pp_det_sast_resnet50vd | SAST | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_sast_icdar15.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_icdar15_v2.0_train.tar) | [SAST](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_det_sast_en.md) |
| en_mm_det_denetpp_resnet50 | DBNet++ | ResNet50 | MMOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/mmocr/dbnetpp_resnet50_fpnc_1200e_icdar2015.yaml) | [pth](https://download.openmmlab.com/mmocr/textdet/dbnetpp/dbnetpp_resnet50_fpnc_1200e_icdar2015/dbnetpp_resnet50_fpnc_1200e_icdar2015_20221025_185550-013730aa.pth) | [DBNetpp](https://github.com/open-mmlab/mmocr/blob/main/configs/textdet/dbnetpp/README.md) |
Expand Down
2 changes: 1 addition & 1 deletion docs/en/inference/models_list_thirdparty.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The original model files involved are as follows:
| en_pp_det_OCRv3 | DBNet | MobileNetV3 | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/ch_PP-OCRv3_det_cml.yaml) | [pp-infer](https://paddleocr.bj.bcebos.com/PP-OCRv3/english/en_PP-OCRv3_det_infer.tar) | [en_PP-OCRv3_det](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/models_list_en.md) |
| ml_pp_det_OCRv3 | DBNet | MobileNetV3 | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/ch_PP-OCRv3_det_cml.yaml) | [pp-infer](https://paddleocr.bj.bcebos.com/PP-OCRv3/multilingual/Multilingual_PP-OCRv3_det_infer.tar) | [ml_PP-OCRv3_det](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/models_list_en.md) |
| en_pp_det_dbnet_resnet50vd | DBNet | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_db.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_db_v2.0_train.tar) | [DBNet](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_det_db_en.md) |
| en_pp_det_psenet_resnet50vd | PSE | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_pse.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar) | [PSE](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_overview_en.md) |
| en_pp_det_psenet_resnet50vd | PSE | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_pse.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.1/en_det/det_r50_vd_pse_v2.0_train.tar) | [PSE](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_det_psenet_en.md) |
| en_pp_det_east_resnet50vd | EAST | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_east.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_east_v2.0_train.tar) | [EAST](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_det_east_en.md) |
| en_pp_det_sast_resnet50vd | SAST | ResNet50_vd | PaddleOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/ppocr/det_r50_vd_sast_icdar15.yaml) | [pp-train](https://paddleocr.bj.bcebos.com/dygraph_v2.0/en/det_r50_vd_sast_icdar15_v2.0_train.tar) | [SAST](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.6/doc/doc_en/algorithm_det_sast_en.md) |
| en_mm_det_denetpp_resnet50 | DBNet++ | ResNet50 | MMOCR | [yaml](https://github.com/mindspore-lab/mindocr/tree/main/deploy/py_infer/src/configs/det/mmocr/dbnetpp_resnet50_fpnc_1200e_icdar2015.yaml) | [pth](https://download.openmmlab.com/mmocr/textdet/dbnetpp/dbnetpp_resnet50_fpnc_1200e_icdar2015/dbnetpp_resnet50_fpnc_1200e_icdar2015_20221025_185550-013730aa.pth) | [DBNetpp](https://github.com/open-mmlab/mmocr/blob/main/configs/textdet/dbnetpp/README.md) |
Expand Down