| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
- #
- # 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 ast import literal_eval
- from pydantic import TypeAdapter, ValidationError
- from functools import wraps
- from typing import Dict, List, Tuple, Union, Literal, Optional
- def custom_type(cli_expected_type):
- """Create validator for CLI input conversion and type checking"""
- def validator(cli_input: str) -> cli_expected_type:
- try:
- parsed = literal_eval(cli_input)
- except (ValueError, SyntaxError, TypeError, MemoryError, RecursionError) as exc:
- err = f"""Malformed input:
- - Input: {cli_input!r}
- - Error: {exc}"""
- raise ValueError(err) from exc
- try:
- return TypeAdapter(cli_expected_type).validate_python(parsed)
- except ValidationError as exc:
- err = f"""Invalid input type:
- - Expected: {cli_expected_type}
- - Received: {cli_input!r}
- """
- raise ValueError(err) from exc
- return validator
- PIPELINE_ARGUMENTS = {
- "OCR": [
- {
- "name": "--use_doc_orientation_classify",
- "type": bool,
- "help": "Determines whether to use document orientation classification",
- },
- {
- "name": "--use_doc_unwarping",
- "type": bool,
- "help": "Determines whether to use document unwarping",
- },
- {
- "name": "--use_textline_orientation",
- "type": bool,
- "help": "Determines whether to consider text line orientation",
- },
- {
- "name": "--text_det_limit_side_len",
- "type": int,
- "help": "Sets the side length limit for text detection.",
- },
- {
- "name": "--text_det_limit_type",
- "type": str,
- "help": "Sets the limit type for text detection.",
- },
- {
- "name": "--text_det_thresh",
- "type": float,
- "help": "Sets the threshold for text detection.",
- },
- {
- "name": "--text_det_box_thresh",
- "type": float,
- "help": "Sets the box threshold for text detection.",
- },
- {
- "name": "--text_det_unclip_ratio",
- "type": float,
- "help": "Sets the unclip ratio for text detection.",
- },
- {
- "name": "--text_rec_score_thresh",
- "type": float,
- "help": "Sets the score threshold for text recognition.",
- },
- ],
- "object_detection": [
- {
- "name": "--threshold",
- "type": custom_type(Optional[Union[float, dict[int, float]]]),
- "help": "Sets the threshold for object detection.",
- },
- ],
- "image_classification": [
- {
- "name": "--topk",
- "type": int,
- "help": "Sets the Top-K value for image classification.",
- },
- ],
- "image_multilabel_classification": [
- {
- "name": "--threshold",
- "type": float,
- "help": "Sets the threshold for image multilabel classification.",
- },
- ],
- "pedestrian_attribute_recognition": [
- {
- "name": "--det_threshold",
- "type": float,
- "help": "Sets the threshold for human detection.",
- },
- {
- "name": "--cls_threshold",
- "type": float,
- "help": "Sets the threshold for pedestrian attribute recognition.",
- },
- ],
- "vehicle_attribute_recognition": [
- {
- "name": "--det_threshold",
- "type": float,
- "help": "Sets the threshold for vehicle detection.",
- },
- {
- "name": "--cls_threshold",
- "type": float,
- "help": "Sets the threshold for vehicle attribute recognition.",
- },
- ],
- "human_keypoint_detection": [
- {
- "name": "--det_threshold",
- "type": custom_type(Optional[float]),
- "help": "Sets the threshold for human detection.",
- },
- ],
- "table_recognition": None,
- "layout_parsing": None,
- "seal_recognition": [
- {
- "name": "--use_doc_orientation_classify",
- "type": bool,
- "help": "Determines whether to use document preprocessing",
- },
- {
- "name": "--use_doc_unwarping",
- "type": bool,
- "help": "Determines whether to use document unwarping",
- },
- {
- "name": "--use_layout_detection",
- "type": bool,
- "help": "Determines whether to use document layout detection",
- },
- {
- "name": "--layout_threshold",
- "type": float,
- "help": "Determines confidence threshold for layout detection",
- },
- {
- "name": "--layout_nms",
- "type": bool,
- "help": "Determines whether to use non maximum suppression",
- },
- {
- "name": "--layout_unclip_ratio",
- "type": float,
- "help": "Determines unclip ratio for layout detection boxes",
- },
- {
- "name": "--layout_merge_bboxes_mode",
- "type": str,
- "help": "Determines merge mode for layout detection bboxes, 'union', 'large' or 'small'",
- },
- {
- "name": "--seal_det_limit_side_len",
- "type": int,
- "help": "Sets the side length limit for text detection.",
- },
- {
- "name": "--seal_det_limit_type",
- "type": str,
- "help": "Sets the limit type for text detection, 'min', 'max'.",
- },
- {
- "name": "--seal_det_thresh",
- "type": float,
- "help": "Sets the threshold for text detection.",
- },
- {
- "name": "--seal_det_box_thresh",
- "type": float,
- "help": "Sets the box threshold for text detection.",
- },
- {
- "name": "--seal_det_unclip_ratio",
- "type": float,
- "help": "Sets the unclip ratio for text detection.",
- },
- {
- "name": "--seal_rec_score_thresh",
- "type": float,
- "help": "Sets the score threshold for text recognition.",
- },
- ],
- "ts_forecast": None,
- "ts_anomaly_detection": None,
- "ts_classification": None,
- "formula_recognition": [
- {
- "name": "--use_layout_detection",
- "type": bool,
- "help": "Determines whether to use layout detection",
- },
- {
- "name": "--use_doc_orientation_classify",
- "type": bool,
- "help": "Determines whether to use document orientation classification",
- },
- {
- "name": "--use_doc_unwarping",
- "type": bool,
- "help": "Determines whether to use document unwarping",
- },
- {
- "name": "--layout_threshold",
- "type": float,
- "help": "Sets the layout threshold for layout detection.",
- },
- {
- "name": "--layout_nms",
- "type": bool,
- "help": "Determines whether to use layout nms",
- },
- {
- "name": "--layout_unclip_ratio",
- "type": float,
- "help": "Sets the layout unclip ratio for layout detection.",
- },
- {
- "name": "--layout_merge_bboxes_mode",
- "type": str,
- "help": "Sets the layout merge bboxes mode for layout detection.",
- },
- ],
- "instance_segmentation": [
- {
- "name": "--threshold",
- "type": custom_type(Optional[float]),
- "help": "Sets the threshold for instance segmentation.",
- },
- ],
- "semantic_segmentation": [
- {
- "name": "--target_size",
- "type": custom_type(Optional[Union[int, Tuple[int, int], Literal[-1]]]),
- "help": "Sets the inference image resolution for semantic segmentation.",
- },
- ],
- "small_object_detection": [
- {
- "name": "--threshold",
- "type": custom_type(Optional[Union[float, dict[int, float]]]),
- "help": "Sets the threshold for small object detection.",
- },
- ],
- "anomaly_detection": None,
- "video_classification": [
- {
- "name": "--topk",
- "type": int,
- "help": "Sets the Top-K value for video classification.",
- },
- ],
- "video_detection": [
- {
- "name": "--nms_thresh",
- "type": float,
- "help": "Sets the NMS threshold for video detection.",
- },
- {
- "name": "--score_thresh",
- "type": float,
- "help": "Sets the confidence threshold for video detection.",
- },
- ],
- "doc_preprocessor": [
- {
- "name": "--use_doc_orientation_classify",
- "type": bool,
- "help": "Determines whether to use document orientation classification.",
- },
- {
- "name": "--use_doc_unwarping",
- "type": bool,
- "help": "Determines whether to use document unwarping.",
- },
- ],
- "rotated_object_detection": [
- {
- "name": "--threshold",
- "type": custom_type(Optional[Union[float, dict[int, float]]]),
- "help": "Sets the threshold for rotated object detection.",
- },
- ],
- "open_vocabulary_detection": [
- {
- "name": "--thresholds",
- "type": custom_type(dict[str, float]),
- "help": "Sets the thresholds for open vocabulary detection.",
- },
- {
- "name": "--prompt",
- "type": str,
- "help": "Sets the prompt for open vocabulary detection.",
- },
- ],
- "open_vocabulary_segmentation": [
- {
- "name": "--prompt_type",
- "type": str,
- "help": "Sets the prompt type for open vocabulary segmentation.",
- },
- {
- "name": "--prompt",
- "type": custom_type(list[list[float]]),
- "help": "Sets the prompt for open vocabulary segmentation.",
- },
- ],
- "3d_bev_detection": None,
- }
|