first commit
Some checks are pending
Build/Publish Develop Docs / deploy (push) Waiting to run

This commit is contained in:
2025-07-02 08:57:16 +03:00
commit 56532cc9a9
1901 changed files with 457695 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .doc_img_orientation_classification import DocImgOrientationClassification
from .doc_vlm import DocVLM
from .formula_recognition import FormulaRecognition
from .layout_detection import LayoutDetection
from .seal_text_detection import SealTextDetection
from .table_cells_detection import TableCellsDetection
from .table_classification import TableClassification
from .table_structure_recognition import TableStructureRecognition
from .text_detection import TextDetection
from .text_image_unwarping import TextImageUnwarping
from .textline_orientation_classification import TextLineOrientationClassification
from .text_recognition import TextRecognition
__all__ = [
"DocImgOrientationClassification",
"DocVLM",
"FormulaRecognition",
"LayoutDetection",
"SealTextDetection",
"TableCellsDetection",
"TableClassification",
"TableStructureRecognition",
"TextDetection",
"TextImageUnwarping",
"TextLineOrientationClassification",
"TextRecognition",
]

View File

@@ -0,0 +1,58 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import abc
from .._utils.cli import (
add_simple_inference_args,
get_subcommand_args,
perform_simple_inference,
)
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
class ImageClassification(PaddleXPredictorWrapper):
def __init__(
self,
*,
topk=None,
**kwargs,
):
self._extra_init_args = {
"topk": topk,
}
super().__init__(**kwargs)
def _get_extra_paddlex_predictor_init_args(self):
return self._extra_init_args
class ImageClassificationSubcommandExecutor(PredictorCLISubcommandExecutor):
def _update_subparser(self, subparser):
add_simple_inference_args(subparser)
subparser.add_argument(
"--topk",
type=int,
help="Top-k value for prediction results.",
)
@property
@abc.abstractmethod
def wrapper_cls(self):
raise NotImplementedError
def execute_with_args(self, args):
params = get_subcommand_args(args)
perform_simple_inference(self.wrapper_cls, params)

View File

@@ -0,0 +1,87 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import abc
from .._utils.cli import (
add_simple_inference_args,
get_subcommand_args,
perform_simple_inference,
str2bool,
)
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
class ObjectDetection(PaddleXPredictorWrapper):
def __init__(
self,
*,
img_size=None,
threshold=None,
layout_nms=None,
layout_unclip_ratio=None,
layout_merge_bboxes_mode=None,
**kwargs,
):
self._extra_init_args = {
"img_size": img_size,
"threshold": threshold,
"layout_nms": layout_nms,
"layout_unclip_ratio": layout_unclip_ratio,
"layout_merge_bboxes_mode": layout_merge_bboxes_mode,
}
super().__init__(**kwargs)
def _get_extra_paddlex_predictor_init_args(self):
return self._extra_init_args
class ObjectDetectionSubcommandExecutor(PredictorCLISubcommandExecutor):
def _update_subparser(self, subparser):
add_simple_inference_args(subparser)
subparser.add_argument(
"--img_size",
type=int,
help="Input image size (w, h).",
)
subparser.add_argument(
"--threshold",
type=float,
help="Threshold for filtering out low-confidence predictions.",
)
subparser.add_argument(
"--layout_nms",
type=str2bool,
help="Whether to use layout-aware NMS.",
)
subparser.add_argument(
"--layout_unclip_ratio",
type=float,
help="Ratio of unclipping the bounding box.",
)
subparser.add_argument(
"--layout_merge_bboxes_mode",
type=str,
help="Mode for merging bounding boxes.",
)
@property
@abc.abstractmethod
def wrapper_cls(self):
raise NotImplementedError
def execute_with_args(self, args):
params = get_subcommand_args(args)
perform_simple_inference(self.wrapper_cls, params)

View File

@@ -0,0 +1,75 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class TextDetectionMixin:
def __init__(
self,
*,
limit_side_len=None,
limit_type=None,
thresh=None,
box_thresh=None,
unclip_ratio=None,
input_shape=None,
**kwargs,
):
self._extra_init_args = {
"limit_side_len": limit_side_len,
"limit_type": limit_type,
"thresh": thresh,
"box_thresh": box_thresh,
"unclip_ratio": unclip_ratio,
"input_shape": input_shape,
}
super().__init__(**kwargs)
def _get_extra_paddlex_predictor_init_args(self):
return self._extra_init_args
class TextDetectionSubcommandExecutorMixin:
def _add_text_detection_args(self, subparser):
subparser.add_argument(
"--limit_side_len",
type=int,
help="This sets a limit on the side length of the input image for the model.",
)
subparser.add_argument(
"--limit_type",
type=str,
help="This determines how the side length limit is applied to the input image before feeding it into the model.",
)
subparser.add_argument(
"--thresh",
type=float,
help="Detection pixel threshold for the model. Pixels with scores greater than this threshold in the output probability map are considered text pixels.",
)
subparser.add_argument(
"--box_thresh",
type=float,
help="Detection box threshold for the model. A detection result is considered a text region if the average score of all pixels within the border of the result is greater than this threshold.",
)
subparser.add_argument(
"--unclip_ratio",
type=float,
help="Expansion coefficient, which expands the text region using this method. The larger the value, the larger the expansion area.",
)
subparser.add_argument(
"--input_shape",
nargs=3,
type=int,
metavar=("C", "H", "W"),
help="Input shape of the model.",
)

98
paddleocr/_models/base.py Normal file
View File

@@ -0,0 +1,98 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import abc
from paddlex import create_predictor
from .._abstract import CLISubcommandExecutor
from .._common_args import (
add_common_cli_opts,
parse_common_args,
prepare_common_init_args,
)
_DEFAULT_ENABLE_HPI = False
class PaddleXPredictorWrapper(metaclass=abc.ABCMeta):
def __init__(
self,
*,
model_name=None,
model_dir=None,
**common_args,
):
super().__init__()
self._model_name = (
model_name if model_name is not None else self.default_model_name
)
self._model_dir = model_dir
self._common_args = parse_common_args(
common_args, default_enable_hpi=_DEFAULT_ENABLE_HPI
)
self.paddlex_predictor = self._create_paddlex_predictor()
@property
@abc.abstractmethod
def default_model_name(self):
raise NotImplementedError
def predict_iter(self, *args, **kwargs):
return self.paddlex_predictor.predict(*args, **kwargs)
def predict(self, *args, **kwargs):
result = list(self.predict_iter(*args, **kwargs))
return result
@classmethod
@abc.abstractmethod
def get_cli_subcommand_executor(cls):
raise NotImplementedError
def _get_extra_paddlex_predictor_init_args(self):
return {}
def _create_paddlex_predictor(self):
kwargs = prepare_common_init_args(self._model_name, self._common_args)
kwargs = {**self._get_extra_paddlex_predictor_init_args(), **kwargs}
# Should we check model names?
return create_predictor(
model_name=self._model_name, model_dir=self._model_dir, **kwargs
)
class PredictorCLISubcommandExecutor(CLISubcommandExecutor):
@property
@abc.abstractmethod
def subparser_name(self):
raise NotImplementedError
def add_subparser(self, subparsers):
subparser = subparsers.add_parser(name=self.subparser_name)
self._update_subparser(subparser)
subparser.add_argument("--model_name", type=str, help="Name of the model.")
subparser.add_argument(
"--model_dir", type=str, help="Directory where the model is stored."
)
add_common_cli_opts(
subparser,
default_enable_hpi=_DEFAULT_ENABLE_HPI,
allow_multiple_devices=False,
)
return subparser
@abc.abstractmethod
def _update_subparser(self, subparser):
raise NotImplementedError

View File

@@ -0,0 +1,40 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ._image_classification import (
ImageClassification,
ImageClassificationSubcommandExecutor,
)
class DocImgOrientationClassification(ImageClassification):
@property
def default_model_name(self):
return "PP-LCNet_x1_0_doc_ori"
@classmethod
def get_cli_subcommand_executor(cls):
return DocImgOrientationClassificationSubcommandExecutor()
class DocImgOrientationClassificationSubcommandExecutor(
ImageClassificationSubcommandExecutor
):
@property
def subparser_name(self):
return "doc_img_orientation_classification"
@property
def wrapper_cls(self):
return DocImgOrientationClassification

View File

@@ -0,0 +1,63 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from paddlex.utils.pipeline_arguments import custom_type
from .._utils.cli import (
add_simple_inference_args,
get_subcommand_args,
perform_simple_inference,
)
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
from paddlex.utils.pipeline_arguments import custom_type
class DocVLM(PaddleXPredictorWrapper):
def __init__(
self,
*args,
**kwargs,
):
self._extra_init_args = {}
super().__init__(*args, **kwargs)
@property
def default_model_name(self):
return "PP-DocBee2-3B"
@classmethod
def get_cli_subcommand_executor(cls):
return DocVLMSubcommandExecutor()
def _get_extra_paddlex_predictor_init_args(self):
return self._extra_init_args
class DocVLMSubcommandExecutor(PredictorCLISubcommandExecutor):
input_validator = staticmethod(custom_type(dict))
@property
def subparser_name(self):
return "doc_vlm"
def _update_subparser(self, subparser):
add_simple_inference_args(
subparser,
input_help='Input dict, e.g. `{"image": "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/medal_table.png", "query": "Recognize this table"}`.',
)
def execute_with_args(self, args):
params = get_subcommand_args(args)
params["input"] = self.input_validator(params["input"])
perform_simple_inference(DocVLM, params)

View File

@@ -0,0 +1,54 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .._utils.cli import (
add_simple_inference_args,
get_subcommand_args,
perform_simple_inference,
)
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
class FormulaRecognition(PaddleXPredictorWrapper):
def __init__(
self,
*args,
**kwargs,
):
self._extra_init_args = {}
super().__init__(*args, **kwargs)
@property
def default_model_name(self):
return "PP-FormulaNet_plus-M"
@classmethod
def get_cli_subcommand_executor(cls):
return FormulaRecognitionSubcommandExecutor()
def _get_extra_paddlex_predictor_init_args(self):
return self._extra_init_args
class FormulaRecognitionSubcommandExecutor(PredictorCLISubcommandExecutor):
@property
def subparser_name(self):
return "formula_recognition"
def _update_subparser(self, subparser):
add_simple_inference_args(subparser)
def execute_with_args(self, args):
params = get_subcommand_args(args)
perform_simple_inference(FormulaRecognition, params)

View File

@@ -0,0 +1,38 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ._object_detection import (
ObjectDetection,
ObjectDetectionSubcommandExecutor,
)
class LayoutDetection(ObjectDetection):
@property
def default_model_name(self):
return "PP-DocLayout_plus-L"
@classmethod
def get_cli_subcommand_executor(cls):
return LayoutDetectionSubcommandExecutor()
class LayoutDetectionSubcommandExecutor(ObjectDetectionSubcommandExecutor):
@property
def subparser_name(self):
return "layout_detection"
@property
def wrapper_cls(self):
return LayoutDetection

View File

@@ -0,0 +1,47 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .._utils.cli import (
add_simple_inference_args,
get_subcommand_args,
perform_simple_inference,
)
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
from ._text_detection import TextDetectionMixin, TextDetectionSubcommandExecutorMixin
class SealTextDetection(TextDetectionMixin, PaddleXPredictorWrapper):
@property
def default_model_name(self):
return "PP-OCRv4_mobile_seal_det"
@classmethod
def get_cli_subcommand_executor(cls):
return SealTextDetectionSubcommandExecutor()
class SealTextDetectionSubcommandExecutor(
TextDetectionSubcommandExecutorMixin, PredictorCLISubcommandExecutor
):
@property
def subparser_name(self):
return "seal_text_detection"
def _update_subparser(self, subparser):
add_simple_inference_args(subparser)
self._add_text_detection_args(subparser)
def execute_with_args(self, args):
params = get_subcommand_args(args)
perform_simple_inference(SealTextDetection, params)

View File

@@ -0,0 +1,38 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ._object_detection import (
ObjectDetection,
ObjectDetectionSubcommandExecutor,
)
class TableCellsDetection(ObjectDetection):
@property
def default_model_name(self):
return "RT-DETR-L_wired_table_cell_det"
@classmethod
def get_cli_subcommand_executor(cls):
return TableCellsDetectionSubcommandExecutor()
class TableCellsDetectionSubcommandExecutor(ObjectDetectionSubcommandExecutor):
@property
def subparser_name(self):
return "table_cells_detection"
@property
def wrapper_cls(self):
return TableCellsDetection

View File

@@ -0,0 +1,38 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ._image_classification import (
ImageClassification,
ImageClassificationSubcommandExecutor,
)
class TableClassification(ImageClassification):
@property
def default_model_name(self):
return "PP-LCNet_x1_0_table_cls"
@classmethod
def get_cli_subcommand_executor(cls):
return TableClassificationSubcommandExecutor()
class TableClassificationSubcommandExecutor(ImageClassificationSubcommandExecutor):
@property
def subparser_name(self):
return "table_classification"
@property
def wrapper_cls(self):
return TableClassification

View File

@@ -0,0 +1,54 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .._utils.cli import (
add_simple_inference_args,
get_subcommand_args,
perform_simple_inference,
)
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
class TableStructureRecognition(PaddleXPredictorWrapper):
def __init__(
self,
*args,
**kwargs,
):
self._extra_init_args = {}
super().__init__(*args, **kwargs)
@property
def default_model_name(self):
return "SLANet"
@classmethod
def get_cli_subcommand_executor(cls):
return TableStructureRecognitionSubcommandExecutor()
def _get_extra_paddlex_predictor_init_args(self):
return self._extra_init_args
class TableStructureRecognitionSubcommandExecutor(PredictorCLISubcommandExecutor):
@property
def subparser_name(self):
return "table_structure_recognition"
def _update_subparser(self, subparser):
add_simple_inference_args(subparser)
def execute_with_args(self, args):
params = get_subcommand_args(args)
perform_simple_inference(TableStructureRecognition, params)

View File

@@ -0,0 +1,47 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .._utils.cli import (
add_simple_inference_args,
get_subcommand_args,
perform_simple_inference,
)
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
from ._text_detection import TextDetectionMixin, TextDetectionSubcommandExecutorMixin
class TextDetection(TextDetectionMixin, PaddleXPredictorWrapper):
@property
def default_model_name(self):
return "PP-OCRv5_server_det"
@classmethod
def get_cli_subcommand_executor(cls):
return TextDetectionSubcommandExecutor()
class TextDetectionSubcommandExecutor(
TextDetectionSubcommandExecutorMixin, PredictorCLISubcommandExecutor
):
@property
def subparser_name(self):
return "text_detection"
def _update_subparser(self, subparser):
add_simple_inference_args(subparser)
self._add_text_detection_args(subparser)
def execute_with_args(self, args):
params = get_subcommand_args(args)
perform_simple_inference(TextDetection, params)

View File

@@ -0,0 +1,54 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .._utils.cli import (
add_simple_inference_args,
get_subcommand_args,
perform_simple_inference,
)
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
class TextImageUnwarping(PaddleXPredictorWrapper):
def __init__(
self,
*args,
**kwargs,
):
self._extra_init_args = {}
super().__init__(*args, **kwargs)
@property
def default_model_name(self):
return "UVDoc"
@classmethod
def get_cli_subcommand_executor(cls):
return TextImageUnwarpingSubcommandExecutor()
def _get_extra_paddlex_predictor_init_args(self):
return self._extra_init_args
class TextImageUnwarpingSubcommandExecutor(PredictorCLISubcommandExecutor):
@property
def subparser_name(self):
return "text_image_unwarping"
def _update_subparser(self, subparser):
add_simple_inference_args(subparser)
def execute_with_args(self, args):
params = get_subcommand_args(args)
perform_simple_inference(TextImageUnwarping, params)

View File

@@ -0,0 +1,64 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .._utils.cli import (
add_simple_inference_args,
get_subcommand_args,
perform_simple_inference,
)
from .base import PaddleXPredictorWrapper, PredictorCLISubcommandExecutor
class TextRecognition(PaddleXPredictorWrapper):
def __init__(
self,
*,
input_shape=None,
**kwargs,
):
self._extra_init_args = {
"input_shape": input_shape,
}
super().__init__(**kwargs)
@property
def default_model_name(self):
return "PP-OCRv5_server_rec"
@classmethod
def get_cli_subcommand_executor(cls):
return TextRecognitionSubcommandExecutor()
def _get_extra_paddlex_predictor_init_args(self):
return self._extra_init_args
class TextRecognitionSubcommandExecutor(PredictorCLISubcommandExecutor):
@property
def subparser_name(self):
return "text_recognition"
def _update_subparser(self, subparser):
add_simple_inference_args(subparser)
subparser.add_argument(
"--input_shape",
nargs=3,
type=int,
metavar=("C", "H", "W"),
help="Input shape of the model.",
)
def execute_with_args(self, args):
params = get_subcommand_args(args)
perform_simple_inference(TextRecognition, params)

View File

@@ -0,0 +1,40 @@
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ._image_classification import (
ImageClassification,
ImageClassificationSubcommandExecutor,
)
class TextLineOrientationClassification(ImageClassification):
@property
def default_model_name(self):
return "PP-LCNet_x0_25_textline_ori"
@classmethod
def get_cli_subcommand_executor(cls):
return TextLineOrientationClassificationSubcommandExecutor()
class TextLineOrientationClassificationSubcommandExecutor(
ImageClassificationSubcommandExecutor
):
@property
def subparser_name(self):
return "textline_orientation_classification"
@property
def wrapper_cls(self):
return TextLineOrientationClassification