paddleocr 0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- paddleocr/__init__.py +65 -0
- paddleocr/__main__.py +39 -0
- paddleocr/_abstract.py +25 -0
- paddleocr/_cli.py +118 -0
- paddleocr/_common_args.py +142 -0
- paddleocr/_constants.py +21 -0
- paddleocr/_env.py +19 -0
- paddleocr/_mkldnn_blocklists.py +31 -0
- paddleocr/_models/__init__.py +41 -0
- paddleocr/_models/_image_classification.py +52 -0
- paddleocr/_models/_object_detection.py +87 -0
- paddleocr/_models/_text_detection.py +75 -0
- paddleocr/_models/base.py +108 -0
- paddleocr/_models/doc_img_orientation_classification.py +40 -0
- paddleocr/_models/doc_vlm.py +63 -0
- paddleocr/_models/formula_recognition.py +54 -0
- paddleocr/_models/layout_detection.py +38 -0
- paddleocr/_models/seal_text_detection.py +47 -0
- paddleocr/_models/table_cells_detection.py +38 -0
- paddleocr/_models/table_classification.py +38 -0
- paddleocr/_models/table_structure_recognition.py +54 -0
- paddleocr/_models/text_detection.py +47 -0
- paddleocr/_models/text_image_unwarping.py +54 -0
- paddleocr/_models/text_line_orientation_classification.py +40 -0
- paddleocr/_models/text_recognition.py +64 -0
- paddleocr/_pipelines/__init__.py +33 -0
- paddleocr/_pipelines/base.py +133 -0
- paddleocr/_pipelines/doc_preprocessor.py +147 -0
- paddleocr/_pipelines/doc_understanding.py +107 -0
- paddleocr/_pipelines/formula_recognition.py +283 -0
- paddleocr/_pipelines/ocr.py +578 -0
- paddleocr/_pipelines/pp_chatocrv4_doc.py +681 -0
- paddleocr/_pipelines/pp_structurev3.py +736 -0
- paddleocr/_pipelines/seal_recognition.py +375 -0
- paddleocr/_pipelines/table_recognition_v2.py +434 -0
- paddleocr/_pipelines/utils.py +30 -0
- paddleocr/_utils/__init__.py +13 -0
- paddleocr/_utils/cli.py +63 -0
- paddleocr/_utils/deprecation.py +42 -0
- paddleocr/_utils/logging.py +39 -0
- paddleocr/_version.py +20 -0
- paddleocr-0.0.0.dist-info/LICENSE +201 -0
- paddleocr-0.0.0.dist-info/METADATA +314 -0
- paddleocr-0.0.0.dist-info/RECORD +47 -0
- paddleocr-0.0.0.dist-info/WHEEL +5 -0
- paddleocr-0.0.0.dist-info/entry_points.txt +2 -0
- paddleocr-0.0.0.dist-info/top_level.txt +1 -0
paddleocr/__init__.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from ._models import (
|
|
16
|
+
DocImgOrientationClassification,
|
|
17
|
+
DocVLM,
|
|
18
|
+
FormulaRecognition,
|
|
19
|
+
LayoutDetection,
|
|
20
|
+
SealTextDetection,
|
|
21
|
+
TableCellsDetection,
|
|
22
|
+
TableClassification,
|
|
23
|
+
TableStructureRecognition,
|
|
24
|
+
TextDetection,
|
|
25
|
+
TextImageUnwarping,
|
|
26
|
+
TextLineOrientationClassification,
|
|
27
|
+
TextRecognition,
|
|
28
|
+
)
|
|
29
|
+
from ._pipelines import (
|
|
30
|
+
DocPreprocessor,
|
|
31
|
+
DocUnderstanding,
|
|
32
|
+
FormulaRecognitionPipeline,
|
|
33
|
+
PaddleOCR,
|
|
34
|
+
PPChatOCRv4Doc,
|
|
35
|
+
PPStructureV3,
|
|
36
|
+
SealRecognition,
|
|
37
|
+
TableRecognitionPipelineV2,
|
|
38
|
+
)
|
|
39
|
+
from ._utils.logging import logger
|
|
40
|
+
from ._version import version as __version__
|
|
41
|
+
|
|
42
|
+
__all__ = [
|
|
43
|
+
"DocImgOrientationClassification",
|
|
44
|
+
"DocVLM",
|
|
45
|
+
"FormulaRecognition",
|
|
46
|
+
"SealTextDetection",
|
|
47
|
+
"LayoutDetection",
|
|
48
|
+
"TableCellsDetection",
|
|
49
|
+
"TableClassification",
|
|
50
|
+
"TableStructureRecognition",
|
|
51
|
+
"TextDetection",
|
|
52
|
+
"TextImageUnwarping",
|
|
53
|
+
"TextLineOrientationClassification",
|
|
54
|
+
"TextRecognition",
|
|
55
|
+
"DocPreprocessor",
|
|
56
|
+
"DocUnderstanding",
|
|
57
|
+
"FormulaRecognitionPipeline",
|
|
58
|
+
"PaddleOCR",
|
|
59
|
+
"PPChatOCRv4Doc",
|
|
60
|
+
"PPStructureV3",
|
|
61
|
+
"SealRecognition",
|
|
62
|
+
"TableRecognitionPipelineV2",
|
|
63
|
+
"logger",
|
|
64
|
+
"__version__",
|
|
65
|
+
]
|
paddleocr/__main__.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
from ._cli import main
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def console_entry() -> int:
|
|
22
|
+
# See https://docs.python.org/3/library/signal.html#note-on-sigpipe
|
|
23
|
+
try:
|
|
24
|
+
# Flush output here to force SIGPIPE to be triggered while inside this
|
|
25
|
+
# try block.
|
|
26
|
+
main()
|
|
27
|
+
sys.stdout.flush()
|
|
28
|
+
sys.stderr.flush()
|
|
29
|
+
except BrokenPipeError:
|
|
30
|
+
# Python flushes standard streams on exit;
|
|
31
|
+
# redirect remaining output to devnull to avoid another BrokenPipeError
|
|
32
|
+
# at shutdown.
|
|
33
|
+
devnull = os.open(os.devnull, os.O_WRONLY)
|
|
34
|
+
os.dup2(devnull, sys.stdout.fileno())
|
|
35
|
+
sys.exit(1)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
console_entry()
|
paddleocr/_abstract.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import abc
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CLISubcommandExecutor(metaclass=abc.ABCMeta):
|
|
19
|
+
@abc.abstractmethod
|
|
20
|
+
def add_subparser(self, subparsers):
|
|
21
|
+
raise NotImplementedError
|
|
22
|
+
|
|
23
|
+
@abc.abstractmethod
|
|
24
|
+
def execute_with_args(self, args):
|
|
25
|
+
raise NotImplementedError
|
paddleocr/_cli.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import argparse
|
|
16
|
+
import logging
|
|
17
|
+
import subprocess
|
|
18
|
+
import sys
|
|
19
|
+
import warnings
|
|
20
|
+
|
|
21
|
+
from ._models import (
|
|
22
|
+
DocImgOrientationClassification,
|
|
23
|
+
DocVLM,
|
|
24
|
+
FormulaRecognition,
|
|
25
|
+
LayoutDetection,
|
|
26
|
+
SealTextDetection,
|
|
27
|
+
TableCellsDetection,
|
|
28
|
+
TableClassification,
|
|
29
|
+
TableStructureRecognition,
|
|
30
|
+
TextDetection,
|
|
31
|
+
TextImageUnwarping,
|
|
32
|
+
TextLineOrientationClassification,
|
|
33
|
+
TextRecognition,
|
|
34
|
+
)
|
|
35
|
+
from ._pipelines import (
|
|
36
|
+
DocPreprocessor,
|
|
37
|
+
DocUnderstanding,
|
|
38
|
+
FormulaRecognitionPipeline,
|
|
39
|
+
PaddleOCR,
|
|
40
|
+
PPChatOCRv4Doc,
|
|
41
|
+
PPStructureV3,
|
|
42
|
+
SealRecognition,
|
|
43
|
+
TableRecognitionPipelineV2,
|
|
44
|
+
)
|
|
45
|
+
from ._version import version
|
|
46
|
+
from ._utils.deprecation import CLIDeprecationWarning
|
|
47
|
+
from ._utils.logging import logger
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _register_pipelines(subparsers):
|
|
51
|
+
for cls in [
|
|
52
|
+
DocPreprocessor,
|
|
53
|
+
DocUnderstanding,
|
|
54
|
+
FormulaRecognitionPipeline,
|
|
55
|
+
PaddleOCR,
|
|
56
|
+
PPChatOCRv4Doc,
|
|
57
|
+
PPStructureV3,
|
|
58
|
+
SealRecognition,
|
|
59
|
+
TableRecognitionPipelineV2,
|
|
60
|
+
]:
|
|
61
|
+
subcommand_executor = cls.get_cli_subcommand_executor()
|
|
62
|
+
subparser = subcommand_executor.add_subparser(subparsers)
|
|
63
|
+
subparser.set_defaults(executor=subcommand_executor.execute_with_args)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _register_models(subparsers):
|
|
67
|
+
for cls in [
|
|
68
|
+
DocImgOrientationClassification,
|
|
69
|
+
DocVLM,
|
|
70
|
+
FormulaRecognition,
|
|
71
|
+
LayoutDetection,
|
|
72
|
+
SealTextDetection,
|
|
73
|
+
TableCellsDetection,
|
|
74
|
+
TableClassification,
|
|
75
|
+
TableStructureRecognition,
|
|
76
|
+
TextDetection,
|
|
77
|
+
TextImageUnwarping,
|
|
78
|
+
TextLineOrientationClassification,
|
|
79
|
+
TextRecognition,
|
|
80
|
+
]:
|
|
81
|
+
subcommand_executor = cls.get_cli_subcommand_executor()
|
|
82
|
+
subparser = subcommand_executor.add_subparser(subparsers)
|
|
83
|
+
subparser.set_defaults(executor=subcommand_executor.execute_with_args)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _register_install_hpi_deps_command(subparsers):
|
|
87
|
+
def _install_hpi_deps(args):
|
|
88
|
+
hpip = f"hpi-{args.variant}"
|
|
89
|
+
try:
|
|
90
|
+
subprocess.check_call(["paddlex", "--install", hpip])
|
|
91
|
+
subprocess.check_call(["paddlex", "--install", "paddle2onnx"])
|
|
92
|
+
except subprocess.CalledProcessError:
|
|
93
|
+
sys.exit("Failed to install dependencies")
|
|
94
|
+
|
|
95
|
+
subparser = subparsers.add_parser("install_hpi_deps")
|
|
96
|
+
subparser.add_argument("variant", type=str, choices=["cpu", "gpu", "npu"])
|
|
97
|
+
subparser.set_defaults(executor=_install_hpi_deps)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _parse_args():
|
|
101
|
+
parser = argparse.ArgumentParser(prog="paddleocr")
|
|
102
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {version}")
|
|
103
|
+
subparsers = parser.add_subparsers(dest="subcommand")
|
|
104
|
+
_register_pipelines(subparsers)
|
|
105
|
+
_register_models(subparsers)
|
|
106
|
+
_register_install_hpi_deps_command(subparsers)
|
|
107
|
+
return parser.parse_args()
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _execute(args):
|
|
111
|
+
args.executor(args)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def main():
|
|
115
|
+
logger.setLevel(logging.INFO)
|
|
116
|
+
warnings.filterwarnings("default", category=CLIDeprecationWarning)
|
|
117
|
+
args = _parse_args()
|
|
118
|
+
_execute(args)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from paddlex.inference import PaddlePredictorOption
|
|
16
|
+
from paddlex.utils.device import get_default_device, parse_device
|
|
17
|
+
|
|
18
|
+
from ._constants import (
|
|
19
|
+
DEFAULT_CPU_THREADS,
|
|
20
|
+
DEFAULT_DEVICE,
|
|
21
|
+
DEFAULT_ENABLE_MKLDNN,
|
|
22
|
+
DEFAULT_MIN_SUBGRAPH_SIZE,
|
|
23
|
+
DEFAULT_PRECISION,
|
|
24
|
+
DEFAULT_USE_TENSORRT,
|
|
25
|
+
SUPPORTED_PRECISION_LIST,
|
|
26
|
+
)
|
|
27
|
+
from ._utils.cli import str2bool
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def parse_common_args(kwargs, *, default_enable_hpi):
|
|
31
|
+
default_vals = {
|
|
32
|
+
"device": DEFAULT_DEVICE,
|
|
33
|
+
"enable_hpi": default_enable_hpi,
|
|
34
|
+
"use_tensorrt": DEFAULT_USE_TENSORRT,
|
|
35
|
+
"min_subgraph_size": DEFAULT_MIN_SUBGRAPH_SIZE,
|
|
36
|
+
"precision": DEFAULT_PRECISION,
|
|
37
|
+
"enable_mkldnn": DEFAULT_ENABLE_MKLDNN,
|
|
38
|
+
"cpu_threads": DEFAULT_CPU_THREADS,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
unknown_names = kwargs.keys() - default_vals.keys()
|
|
42
|
+
for name in unknown_names:
|
|
43
|
+
raise ValueError(f"Unknown argument: {name}")
|
|
44
|
+
|
|
45
|
+
kwargs = {**default_vals, **kwargs}
|
|
46
|
+
|
|
47
|
+
if kwargs["precision"] not in SUPPORTED_PRECISION_LIST:
|
|
48
|
+
raise ValueError(
|
|
49
|
+
f"Invalid precision: {kwargs['precision']}. Supported values are: {SUPPORTED_PRECISION_LIST}."
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
kwargs["use_pptrt"] = kwargs.pop("use_tensorrt")
|
|
53
|
+
kwargs["pptrt_min_subgraph_size"] = kwargs.pop("min_subgraph_size")
|
|
54
|
+
kwargs["pptrt_precision"] = kwargs.pop("precision")
|
|
55
|
+
|
|
56
|
+
return kwargs
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def prepare_common_init_args(model_name, common_args):
|
|
60
|
+
device = common_args["device"]
|
|
61
|
+
if device is None:
|
|
62
|
+
device = get_default_device()
|
|
63
|
+
device_type, _ = parse_device(device)
|
|
64
|
+
|
|
65
|
+
init_kwargs = {"device": device}
|
|
66
|
+
init_kwargs["use_hpip"] = common_args["enable_hpi"]
|
|
67
|
+
|
|
68
|
+
pp_option = PaddlePredictorOption(model_name)
|
|
69
|
+
if device_type == "gpu":
|
|
70
|
+
if common_args["use_pptrt"]:
|
|
71
|
+
if common_args["pptrt_precision"] == "fp32":
|
|
72
|
+
pp_option.run_mode = "trt_fp32"
|
|
73
|
+
else:
|
|
74
|
+
assert common_args["pptrt_precision"] == "fp16", common_args[
|
|
75
|
+
"pptrt_precision"
|
|
76
|
+
]
|
|
77
|
+
pp_option.run_mode = "trt_fp16"
|
|
78
|
+
elif device_type == "cpu":
|
|
79
|
+
enable_mkldnn = common_args["enable_mkldnn"]
|
|
80
|
+
if enable_mkldnn is None:
|
|
81
|
+
from paddle.inference import Config
|
|
82
|
+
|
|
83
|
+
if hasattr(Config, "set_mkldnn_cache_capacity"):
|
|
84
|
+
enable_mkldnn = True
|
|
85
|
+
else:
|
|
86
|
+
enable_mkldnn = False
|
|
87
|
+
if enable_mkldnn:
|
|
88
|
+
pp_option.run_mode = "mkldnn"
|
|
89
|
+
pp_option.cpu_threads = common_args["cpu_threads"]
|
|
90
|
+
init_kwargs["pp_option"] = pp_option
|
|
91
|
+
|
|
92
|
+
return init_kwargs
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def add_common_cli_opts(parser, *, default_enable_hpi, allow_multiple_devices):
|
|
96
|
+
if allow_multiple_devices:
|
|
97
|
+
help_ = "Device(s) to use for inference, e.g., `cpu`, `gpu`, `npu`, `gpu:0`, `gpu:0,1`. If multiple devices are specified, inference will be performed in parallel. Note that parallel inference is not always supported. By default, GPU 0 will be used if available; otherwise, the CPU will be used."
|
|
98
|
+
else:
|
|
99
|
+
help_ = "Device to use for inference, e.g., `cpu`, `gpu`, `npu`, `gpu:0`. By default, GPU 0 will be used if available; otherwise, the CPU will be used."
|
|
100
|
+
parser.add_argument(
|
|
101
|
+
"--device",
|
|
102
|
+
type=str,
|
|
103
|
+
default=DEFAULT_DEVICE,
|
|
104
|
+
help=help_,
|
|
105
|
+
)
|
|
106
|
+
parser.add_argument(
|
|
107
|
+
"--enable_hpi",
|
|
108
|
+
type=str2bool,
|
|
109
|
+
default=default_enable_hpi,
|
|
110
|
+
help="Enable the high performance inference.",
|
|
111
|
+
)
|
|
112
|
+
parser.add_argument(
|
|
113
|
+
"--use_tensorrt",
|
|
114
|
+
type=str2bool,
|
|
115
|
+
default=DEFAULT_USE_TENSORRT,
|
|
116
|
+
help="Whether to use the Paddle Inference TensorRT subgraph engine.",
|
|
117
|
+
)
|
|
118
|
+
parser.add_argument(
|
|
119
|
+
"--min_subgraph_size",
|
|
120
|
+
type=int,
|
|
121
|
+
default=DEFAULT_MIN_SUBGRAPH_SIZE,
|
|
122
|
+
help="Minimum subgraph size for TensorRT when using the Paddle Inference TensorRT subgraph engine.",
|
|
123
|
+
)
|
|
124
|
+
parser.add_argument(
|
|
125
|
+
"--precision",
|
|
126
|
+
type=str,
|
|
127
|
+
default=DEFAULT_PRECISION,
|
|
128
|
+
choices=SUPPORTED_PRECISION_LIST,
|
|
129
|
+
help="Precision for TensorRT when using the Paddle Inference TensorRT subgraph engine.",
|
|
130
|
+
)
|
|
131
|
+
parser.add_argument(
|
|
132
|
+
"--enable_mkldnn",
|
|
133
|
+
type=str2bool,
|
|
134
|
+
default=DEFAULT_ENABLE_MKLDNN,
|
|
135
|
+
help="Enable oneDNN (formerly MKL-DNN) acceleration for inference. By default, oneDNN will be used when available, except for models and pipelines that have known oneDNN issues.",
|
|
136
|
+
)
|
|
137
|
+
parser.add_argument(
|
|
138
|
+
"--cpu_threads",
|
|
139
|
+
type=int,
|
|
140
|
+
default=DEFAULT_CPU_THREADS,
|
|
141
|
+
help="Number of threads to use for inference on CPUs.",
|
|
142
|
+
)
|
paddleocr/_constants.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
DEFAULT_DEVICE = None
|
|
16
|
+
DEFAULT_USE_TENSORRT = False
|
|
17
|
+
DEFAULT_MIN_SUBGRAPH_SIZE = 3
|
|
18
|
+
DEFAULT_PRECISION = "fp32"
|
|
19
|
+
DEFAULT_ENABLE_MKLDNN = None
|
|
20
|
+
DEFAULT_CPU_THREADS = 10
|
|
21
|
+
SUPPORTED_PRECISION_LIST = ["fp32", "fp16"]
|
paddleocr/_env.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
|
|
17
|
+
DISABLE_AUTO_LOGGING_CONFIG = (
|
|
18
|
+
os.getenv("PADDLEOCR_DISABLE_AUTO_LOGGING_CONFIG", "0") == "1"
|
|
19
|
+
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
PIPELINE_MKLDNN_BLOCKLIST = [
|
|
16
|
+
"formula_recognition",
|
|
17
|
+
"table_recognition_v2",
|
|
18
|
+
"PP-StructureV3",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
MODEL_MKLDNN_BLOCKLIST = [
|
|
22
|
+
"SLANeXt_wired",
|
|
23
|
+
"SLANeXt_wireless",
|
|
24
|
+
"LaTeX_OCR_rec",
|
|
25
|
+
"PP-FormulaNet-L",
|
|
26
|
+
"PP-FormulaNet-S",
|
|
27
|
+
"UniMERNet",
|
|
28
|
+
"PP-FormulaNet_plus-L",
|
|
29
|
+
"PP-FormulaNet_plus-M",
|
|
30
|
+
"PP-FormulaNet_plus-S",
|
|
31
|
+
]
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
from .doc_img_orientation_classification import DocImgOrientationClassification
|
|
16
|
+
from .doc_vlm import DocVLM
|
|
17
|
+
from .formula_recognition import FormulaRecognition
|
|
18
|
+
from .layout_detection import LayoutDetection
|
|
19
|
+
from .seal_text_detection import SealTextDetection
|
|
20
|
+
from .table_cells_detection import TableCellsDetection
|
|
21
|
+
from .table_classification import TableClassification
|
|
22
|
+
from .table_structure_recognition import TableStructureRecognition
|
|
23
|
+
from .text_detection import TextDetection
|
|
24
|
+
from .text_image_unwarping import TextImageUnwarping
|
|
25
|
+
from .text_line_orientation_classification import TextLineOrientationClassification
|
|
26
|
+
from .text_recognition import TextRecognition
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"DocImgOrientationClassification",
|
|
30
|
+
"DocVLM",
|
|
31
|
+
"FormulaRecognition",
|
|
32
|
+
"LayoutDetection",
|
|
33
|
+
"SealTextDetection",
|
|
34
|
+
"TableCellsDetection",
|
|
35
|
+
"TableClassification",
|
|
36
|
+
"TableStructureRecognition",
|
|
37
|
+
"TextDetection",
|
|
38
|
+
"TextImageUnwarping",
|
|
39
|
+
"TextLineOrientationClassification",
|
|
40
|
+
"TextRecognition",
|
|
41
|
+
]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import abc
|
|
16
|
+
|
|
17
|
+
from .._utils.cli import (
|
|
18
|
+
add_simple_inference_args,
|
|
19
|
+
get_subcommand_args,
|
|
20
|
+
perform_simple_inference,
|
|
21
|
+
)
|
|
22
|
+
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ImageClassification(PaddleXPredictorWrapper):
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
*,
|
|
29
|
+
topk=None,
|
|
30
|
+
**kwargs,
|
|
31
|
+
):
|
|
32
|
+
self._extra_init_args = {
|
|
33
|
+
"topk": topk,
|
|
34
|
+
}
|
|
35
|
+
super().__init__(**kwargs)
|
|
36
|
+
|
|
37
|
+
def _get_extra_paddlex_predictor_init_args(self):
|
|
38
|
+
return self._extra_init_args
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class ImageClassificationSubcommandExecutor(PredictorCLISubcommandExecutor):
|
|
42
|
+
def _update_subparser(self, subparser):
|
|
43
|
+
add_simple_inference_args(subparser)
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
@abc.abstractmethod
|
|
47
|
+
def wrapper_cls(self):
|
|
48
|
+
raise NotImplementedError
|
|
49
|
+
|
|
50
|
+
def execute_with_args(self, args):
|
|
51
|
+
params = get_subcommand_args(args)
|
|
52
|
+
perform_simple_inference(self.wrapper_cls, params)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
import abc
|
|
16
|
+
|
|
17
|
+
from .._utils.cli import (
|
|
18
|
+
add_simple_inference_args,
|
|
19
|
+
get_subcommand_args,
|
|
20
|
+
perform_simple_inference,
|
|
21
|
+
str2bool,
|
|
22
|
+
)
|
|
23
|
+
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ObjectDetection(PaddleXPredictorWrapper):
|
|
27
|
+
def __init__(
|
|
28
|
+
self,
|
|
29
|
+
*,
|
|
30
|
+
img_size=None,
|
|
31
|
+
threshold=None,
|
|
32
|
+
layout_nms=None,
|
|
33
|
+
layout_unclip_ratio=None,
|
|
34
|
+
layout_merge_bboxes_mode=None,
|
|
35
|
+
**kwargs,
|
|
36
|
+
):
|
|
37
|
+
self._extra_init_args = {
|
|
38
|
+
"img_size": img_size,
|
|
39
|
+
"threshold": threshold,
|
|
40
|
+
"layout_nms": layout_nms,
|
|
41
|
+
"layout_unclip_ratio": layout_unclip_ratio,
|
|
42
|
+
"layout_merge_bboxes_mode": layout_merge_bboxes_mode,
|
|
43
|
+
}
|
|
44
|
+
super().__init__(**kwargs)
|
|
45
|
+
|
|
46
|
+
def _get_extra_paddlex_predictor_init_args(self):
|
|
47
|
+
return self._extra_init_args
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class ObjectDetectionSubcommandExecutor(PredictorCLISubcommandExecutor):
|
|
51
|
+
def _update_subparser(self, subparser):
|
|
52
|
+
add_simple_inference_args(subparser)
|
|
53
|
+
|
|
54
|
+
subparser.add_argument(
|
|
55
|
+
"--img_size",
|
|
56
|
+
type=int,
|
|
57
|
+
help="The input image size (w, h).",
|
|
58
|
+
)
|
|
59
|
+
subparser.add_argument(
|
|
60
|
+
"--threshold",
|
|
61
|
+
type=float,
|
|
62
|
+
help="The threshold for filtering out low-confidence predictions.",
|
|
63
|
+
)
|
|
64
|
+
subparser.add_argument(
|
|
65
|
+
"--layout_nms",
|
|
66
|
+
type=str2bool,
|
|
67
|
+
help="Whether to use layout-aware NMS.",
|
|
68
|
+
)
|
|
69
|
+
subparser.add_argument(
|
|
70
|
+
"--layout_unclip_ratio",
|
|
71
|
+
type=float,
|
|
72
|
+
help="The ratio of unclipping the bounding box.",
|
|
73
|
+
)
|
|
74
|
+
subparser.add_argument(
|
|
75
|
+
"--layout_merge_bboxes_mode",
|
|
76
|
+
type=str,
|
|
77
|
+
help="The mode for merging bounding boxes.",
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
@property
|
|
81
|
+
@abc.abstractmethod
|
|
82
|
+
def wrapper_cls(self):
|
|
83
|
+
raise NotImplementedError
|
|
84
|
+
|
|
85
|
+
def execute_with_args(self, args):
|
|
86
|
+
params = get_subcommand_args(args)
|
|
87
|
+
perform_simple_inference(self.wrapper_cls, params)
|