pipeline_arguments.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  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. from ast import literal_eval
  15. from pydantic import TypeAdapter, ValidationError
  16. from functools import wraps
  17. from typing import Dict, List, Tuple, Union, Literal, Optional
  18. def custom_type(cli_expected_type):
  19. """Create validator for CLI input conversion and type checking"""
  20. def validator(cli_input: str) -> cli_expected_type:
  21. try:
  22. parsed = literal_eval(cli_input)
  23. except (ValueError, SyntaxError, TypeError, MemoryError, RecursionError) as exc:
  24. err = f"""Malformed input:
  25. - Input: {cli_input!r}
  26. - Error: {exc}"""
  27. raise ValueError(err) from exc
  28. try:
  29. return TypeAdapter(cli_expected_type).validate_python(parsed)
  30. except ValidationError as exc:
  31. err = f"""Invalid input type:
  32. - Expected: {cli_expected_type}
  33. - Received: {cli_input!r}
  34. """
  35. raise ValueError(err) from exc
  36. return validator
  37. PIPELINE_ARGUMENTS = {
  38. "OCR": [
  39. {
  40. "name": "--use_doc_orientation_classify",
  41. "type": bool,
  42. "help": "Determines whether to use document orientation classification",
  43. },
  44. {
  45. "name": "--use_doc_unwarping",
  46. "type": bool,
  47. "help": "Determines whether to use document unwarping",
  48. },
  49. {
  50. "name": "--use_textline_orientation",
  51. "type": bool,
  52. "help": "Determines whether to consider text line orientation",
  53. },
  54. {
  55. "name": "--text_det_limit_side_len",
  56. "type": int,
  57. "help": "Sets the side length limit for text detection.",
  58. },
  59. {
  60. "name": "--text_det_limit_type",
  61. "type": str,
  62. "help": "Sets the limit type for text detection.",
  63. },
  64. {
  65. "name": "--text_det_thresh",
  66. "type": float,
  67. "help": "Sets the threshold for text detection.",
  68. },
  69. {
  70. "name": "--text_det_box_thresh",
  71. "type": float,
  72. "help": "Sets the box threshold for text detection.",
  73. },
  74. {
  75. "name": "--text_det_unclip_ratio",
  76. "type": float,
  77. "help": "Sets the unclip ratio for text detection.",
  78. },
  79. {
  80. "name": "--text_rec_score_thresh",
  81. "type": float,
  82. "help": "Sets the score threshold for text recognition.",
  83. },
  84. ],
  85. "object_detection": [
  86. {
  87. "name": "--threshold",
  88. "type": custom_type(Optional[Union[float, Dict[int, float]]]),
  89. "help": "Sets the threshold for object detection.",
  90. },
  91. ],
  92. "image_classification": [
  93. {
  94. "name": "--topk",
  95. "type": int,
  96. "help": "Sets the Top-K value for image classification.",
  97. },
  98. ],
  99. "image_multilabel_classification": [
  100. {
  101. "name": "--threshold",
  102. "type": float,
  103. "help": "Sets the threshold for image multilabel classification.",
  104. },
  105. ],
  106. "pedestrian_attribute_recognition": [
  107. {
  108. "name": "--det_threshold",
  109. "type": float,
  110. "help": "Sets the threshold for human detection.",
  111. },
  112. {
  113. "name": "--cls_threshold",
  114. "type": float,
  115. "help": "Sets the threshold for pedestrian attribute recognition.",
  116. },
  117. ],
  118. "vehicle_attribute_recognition": [
  119. {
  120. "name": "--det_threshold",
  121. "type": float,
  122. "help": "Sets the threshold for vehicle detection.",
  123. },
  124. {
  125. "name": "--cls_threshold",
  126. "type": float,
  127. "help": "Sets the threshold for vehicle attribute recognition.",
  128. },
  129. ],
  130. "human_keypoint_detection": [
  131. {
  132. "name": "--det_threshold",
  133. "type": custom_type(Optional[float]),
  134. "help": "Sets the threshold for human detection.",
  135. },
  136. ],
  137. "table_recognition": [
  138. {
  139. "name": "--use_doc_orientation_classify",
  140. "type": bool,
  141. "help": "Determines whether to use document preprocessing",
  142. },
  143. {
  144. "name": "--use_doc_unwarping",
  145. "type": bool,
  146. "help": "Determines whether to use document unwarping",
  147. },
  148. {
  149. "name": "--use_layout_detection",
  150. "type": bool,
  151. "help": "Determines whether to use document layout detection",
  152. },
  153. {
  154. "name": "--use_ocr_model",
  155. "type": bool,
  156. "help": "Determines whether to use OCR",
  157. },
  158. {
  159. "name": "--text_det_limit_side_len",
  160. "type": int,
  161. "help": "Sets the side length limit for text detection.",
  162. },
  163. {
  164. "name": "--text_det_limit_type",
  165. "type": str,
  166. "help": "Sets the limit type for text detection.",
  167. },
  168. {
  169. "name": "--text_det_thresh",
  170. "type": float,
  171. "help": "Sets the threshold for text detection.",
  172. },
  173. {
  174. "name": "--text_det_box_thresh",
  175. "type": float,
  176. "help": "Sets the box threshold for text detection.",
  177. },
  178. {
  179. "name": "--text_det_unclip_ratio",
  180. "type": float,
  181. "help": "Sets the unclip ratio for text detection.",
  182. },
  183. {
  184. "name": "--text_rec_score_thresh",
  185. "type": float,
  186. "help": "Sets the score threshold for text recognition.",
  187. },
  188. ],
  189. "table_recognition_v2": [
  190. {
  191. "name": "--use_doc_orientation_classify",
  192. "type": bool,
  193. "help": "Determines whether to use document preprocessing",
  194. },
  195. {
  196. "name": "--use_doc_unwarping",
  197. "type": bool,
  198. "help": "Determines whether to use document unwarping",
  199. },
  200. {
  201. "name": "--use_layout_detection",
  202. "type": bool,
  203. "help": "Determines whether to use document layout detection",
  204. },
  205. {
  206. "name": "--use_ocr_model",
  207. "type": bool,
  208. "help": "Determines whether to use OCR",
  209. },
  210. {
  211. "name": "--text_det_limit_side_len",
  212. "type": int,
  213. "help": "Sets the side length limit for text detection.",
  214. },
  215. {
  216. "name": "--text_det_limit_type",
  217. "type": str,
  218. "help": "Sets the limit type for text detection.",
  219. },
  220. {
  221. "name": "--text_det_thresh",
  222. "type": float,
  223. "help": "Sets the threshold for text detection.",
  224. },
  225. {
  226. "name": "--text_det_box_thresh",
  227. "type": float,
  228. "help": "Sets the box threshold for text detection.",
  229. },
  230. {
  231. "name": "--text_det_unclip_ratio",
  232. "type": float,
  233. "help": "Sets the unclip ratio for text detection.",
  234. },
  235. {
  236. "name": "--text_rec_score_thresh",
  237. "type": float,
  238. "help": "Sets the score threshold for text recognition.",
  239. },
  240. ],
  241. "seal_recognition": [
  242. {
  243. "name": "--use_doc_orientation_classify",
  244. "type": bool,
  245. "help": "Determines whether to use document preprocessing",
  246. },
  247. {
  248. "name": "--use_doc_unwarping",
  249. "type": bool,
  250. "help": "Determines whether to use document unwarping",
  251. },
  252. {
  253. "name": "--use_layout_detection",
  254. "type": bool,
  255. "help": "Determines whether to use document layout detection",
  256. },
  257. {
  258. "name": "--layout_threshold",
  259. "type": float,
  260. "help": "Determines confidence threshold for layout detection",
  261. },
  262. {
  263. "name": "--layout_nms",
  264. "type": bool,
  265. "help": "Determines whether to use non maximum suppression",
  266. },
  267. {
  268. "name": "--layout_unclip_ratio",
  269. "type": float,
  270. "help": "Determines unclip ratio for layout detection boxes",
  271. },
  272. {
  273. "name": "--layout_merge_bboxes_mode",
  274. "type": str,
  275. "help": "Determines merge mode for layout detection bboxes, 'union', 'large' or 'small'",
  276. },
  277. {
  278. "name": "--seal_det_limit_side_len",
  279. "type": int,
  280. "help": "Sets the side length limit for text detection.",
  281. },
  282. {
  283. "name": "--seal_det_limit_type",
  284. "type": str,
  285. "help": "Sets the limit type for text detection, 'min', 'max'.",
  286. },
  287. {
  288. "name": "--seal_det_thresh",
  289. "type": float,
  290. "help": "Sets the threshold for text detection.",
  291. },
  292. {
  293. "name": "--seal_det_box_thresh",
  294. "type": float,
  295. "help": "Sets the box threshold for text detection.",
  296. },
  297. {
  298. "name": "--seal_det_unclip_ratio",
  299. "type": float,
  300. "help": "Sets the unclip ratio for text detection.",
  301. },
  302. {
  303. "name": "--seal_rec_score_thresh",
  304. "type": float,
  305. "help": "Sets the score threshold for text recognition.",
  306. },
  307. ],
  308. "layout_parsing": [
  309. {
  310. "name": "--use_doc_orientation_classify",
  311. "type": bool,
  312. "help": "Determines whether to use document orientation classification",
  313. },
  314. {
  315. "name": "--use_doc_unwarping",
  316. "type": bool,
  317. "help": "Determines whether to use document unwarping",
  318. },
  319. {
  320. "name": "--use_general_ocr",
  321. "type": bool,
  322. "help": "Determines whether to use general ocr",
  323. },
  324. {
  325. "name": "--use_textline_orientation",
  326. "type": bool,
  327. "help": "Determines whether to consider text line orientation",
  328. },
  329. {
  330. "name": "--use_seal_recognition",
  331. "type": bool,
  332. "help": "Determines whether to use seal recognition",
  333. },
  334. {
  335. "name": "--use_table_recognition",
  336. "type": bool,
  337. "help": "Determines whether to use table recognition",
  338. },
  339. {
  340. "name": "--use_formula_recognition",
  341. "type": bool,
  342. "help": "Determines whether to use formula recognition",
  343. },
  344. {
  345. "name": "--layout_threshold",
  346. "type": float,
  347. "help": "Determines confidence threshold for layout detection",
  348. },
  349. {
  350. "name": "--layout_nms",
  351. "type": bool,
  352. "help": "Determines whether to use non maximum suppression",
  353. },
  354. {
  355. "name": "--layout_unclip_ratio",
  356. "type": float,
  357. "help": "Determines unclip ratio for layout detection boxes",
  358. },
  359. {
  360. "name": "--layout_merge_bboxes_mode",
  361. "type": str,
  362. "help": "Determines merge mode for layout detection bboxes, 'union', 'large' or 'small'",
  363. },
  364. {
  365. "name": "--seal_det_limit_side_len",
  366. "type": int,
  367. "help": "Sets the side length limit for text detection.",
  368. },
  369. {
  370. "name": "--seal_det_limit_type",
  371. "type": str,
  372. "help": "Sets the limit type for text detection, 'min', 'max'.",
  373. },
  374. {
  375. "name": "--seal_det_thresh",
  376. "type": float,
  377. "help": "Sets the threshold for text detection.",
  378. },
  379. {
  380. "name": "--seal_det_box_thresh",
  381. "type": float,
  382. "help": "Sets the box threshold for text detection.",
  383. },
  384. {
  385. "name": "--seal_det_unclip_ratio",
  386. "type": float,
  387. "help": "Sets the unclip ratio for text detection.",
  388. },
  389. {
  390. "name": "--seal_rec_score_thresh",
  391. "type": float,
  392. "help": "Sets the score threshold for text recognition.",
  393. },
  394. {
  395. "name": "--text_det_limit_side_len",
  396. "type": int,
  397. "help": "Sets the side length limit for text detection.",
  398. },
  399. {
  400. "name": "--text_det_limit_type",
  401. "type": str,
  402. "help": "Sets the limit type for text detection.",
  403. },
  404. {
  405. "name": "--text_det_thresh",
  406. "type": float,
  407. "help": "Sets the threshold for text detection.",
  408. },
  409. {
  410. "name": "--text_det_box_thresh",
  411. "type": float,
  412. "help": "Sets the box threshold for text detection.",
  413. },
  414. {
  415. "name": "--text_det_unclip_ratio",
  416. "type": float,
  417. "help": "Sets the unclip ratio for text detection.",
  418. },
  419. {
  420. "name": "--text_rec_score_thresh",
  421. "type": float,
  422. "help": "Sets the score threshold for text recognition.",
  423. },
  424. ],
  425. "layout_parsing_v2": [
  426. {
  427. "name": "--use_doc_orientation_classify",
  428. "type": bool,
  429. "help": "Determines whether to use document orientation classification",
  430. },
  431. {
  432. "name": "--use_doc_unwarping",
  433. "type": bool,
  434. "help": "Determines whether to use document unwarping",
  435. },
  436. {
  437. "name": "--use_general_ocr",
  438. "type": bool,
  439. "help": "Determines whether to use general ocr",
  440. },
  441. {
  442. "name": "--use_textline_orientation",
  443. "type": bool,
  444. "help": "Determines whether to consider text line orientation",
  445. },
  446. {
  447. "name": "--use_seal_recognition",
  448. "type": bool,
  449. "help": "Determines whether to use seal recognition",
  450. },
  451. {
  452. "name": "--use_table_recognition",
  453. "type": bool,
  454. "help": "Determines whether to use table recognition",
  455. },
  456. {
  457. "name": "--use_formula_recognition",
  458. "type": bool,
  459. "help": "Determines whether to use formula recognition",
  460. },
  461. {
  462. "name": "--layout_threshold",
  463. "type": float,
  464. "help": "Determines confidence threshold for layout detection",
  465. },
  466. {
  467. "name": "--layout_nms",
  468. "type": bool,
  469. "help": "Determines whether to use non maximum suppression",
  470. },
  471. {
  472. "name": "--layout_unclip_ratio",
  473. "type": float,
  474. "help": "Determines unclip ratio for layout detection boxes",
  475. },
  476. {
  477. "name": "--layout_merge_bboxes_mode",
  478. "type": str,
  479. "help": "Determines merge mode for layout detection bboxes, 'union', 'large' or 'small'",
  480. },
  481. {
  482. "name": "--seal_det_limit_side_len",
  483. "type": int,
  484. "help": "Sets the side length limit for text detection.",
  485. },
  486. {
  487. "name": "--seal_det_limit_type",
  488. "type": str,
  489. "help": "Sets the limit type for text detection, 'min', 'max'.",
  490. },
  491. {
  492. "name": "--seal_det_thresh",
  493. "type": float,
  494. "help": "Sets the threshold for text detection.",
  495. },
  496. {
  497. "name": "--seal_det_box_thresh",
  498. "type": float,
  499. "help": "Sets the box threshold for text detection.",
  500. },
  501. {
  502. "name": "--seal_det_unclip_ratio",
  503. "type": float,
  504. "help": "Sets the unclip ratio for text detection.",
  505. },
  506. {
  507. "name": "--seal_rec_score_thresh",
  508. "type": float,
  509. "help": "Sets the score threshold for text recognition.",
  510. },
  511. {
  512. "name": "--text_det_limit_side_len",
  513. "type": int,
  514. "help": "Sets the side length limit for text detection.",
  515. },
  516. {
  517. "name": "--text_det_limit_type",
  518. "type": str,
  519. "help": "Sets the limit type for text detection.",
  520. },
  521. {
  522. "name": "--text_det_thresh",
  523. "type": float,
  524. "help": "Sets the threshold for text detection.",
  525. },
  526. {
  527. "name": "--text_det_box_thresh",
  528. "type": float,
  529. "help": "Sets the box threshold for text detection.",
  530. },
  531. {
  532. "name": "--text_det_unclip_ratio",
  533. "type": float,
  534. "help": "Sets the unclip ratio for text detection.",
  535. },
  536. {
  537. "name": "--text_rec_score_thresh",
  538. "type": float,
  539. "help": "Sets the score threshold for text recognition.",
  540. },
  541. ],
  542. "ts_forecast": None,
  543. "ts_anomaly_detection": None,
  544. "ts_classification": None,
  545. "formula_recognition": [
  546. {
  547. "name": "--use_layout_detection",
  548. "type": bool,
  549. "help": "Determines whether to use layout detection",
  550. },
  551. {
  552. "name": "--use_doc_orientation_classify",
  553. "type": bool,
  554. "help": "Determines whether to use document orientation classification",
  555. },
  556. {
  557. "name": "--use_doc_unwarping",
  558. "type": bool,
  559. "help": "Determines whether to use document unwarping",
  560. },
  561. {
  562. "name": "--layout_threshold",
  563. "type": float,
  564. "help": "Sets the layout threshold for layout detection.",
  565. },
  566. {
  567. "name": "--layout_nms",
  568. "type": bool,
  569. "help": "Determines whether to use layout nms",
  570. },
  571. {
  572. "name": "--layout_unclip_ratio",
  573. "type": float,
  574. "help": "Sets the layout unclip ratio for layout detection.",
  575. },
  576. {
  577. "name": "--layout_merge_bboxes_mode",
  578. "type": str,
  579. "help": "Sets the layout merge bboxes mode for layout detection.",
  580. },
  581. ],
  582. "instance_segmentation": [
  583. {
  584. "name": "--threshold",
  585. "type": custom_type(Optional[float]),
  586. "help": "Sets the threshold for instance segmentation.",
  587. },
  588. ],
  589. "semantic_segmentation": [
  590. {
  591. "name": "--target_size",
  592. "type": custom_type(Optional[Union[int, Tuple[int, int], Literal[-1]]]),
  593. "help": "Sets the inference image resolution for semantic segmentation.",
  594. },
  595. ],
  596. "small_object_detection": [
  597. {
  598. "name": "--threshold",
  599. "type": custom_type(Optional[Union[float, Dict[int, float]]]),
  600. "help": "Sets the threshold for small object detection.",
  601. },
  602. ],
  603. "anomaly_detection": None,
  604. "video_classification": [
  605. {
  606. "name": "--topk",
  607. "type": int,
  608. "help": "Sets the Top-K value for video classification.",
  609. },
  610. ],
  611. "video_detection": [
  612. {
  613. "name": "--nms_thresh",
  614. "type": float,
  615. "help": "Sets the NMS threshold for video detection.",
  616. },
  617. {
  618. "name": "--score_thresh",
  619. "type": float,
  620. "help": "Sets the confidence threshold for video detection.",
  621. },
  622. ],
  623. "doc_preprocessor": [
  624. {
  625. "name": "--use_doc_orientation_classify",
  626. "type": bool,
  627. "help": "Determines whether to use document orientation classification.",
  628. },
  629. {
  630. "name": "--use_doc_unwarping",
  631. "type": bool,
  632. "help": "Determines whether to use document unwarping.",
  633. },
  634. ],
  635. "rotated_object_detection": [
  636. {
  637. "name": "--threshold",
  638. "type": custom_type(Optional[Union[float, Dict[int, float]]]),
  639. "help": "Sets the threshold for rotated object detection.",
  640. },
  641. ],
  642. "open_vocabulary_detection": [
  643. {
  644. "name": "--thresholds",
  645. "type": custom_type(Dict[str, float]),
  646. "help": "Sets the thresholds for open vocabulary detection.",
  647. },
  648. {
  649. "name": "--prompt",
  650. "type": str,
  651. "help": "Sets the prompt for open vocabulary detection.",
  652. },
  653. ],
  654. "open_vocabulary_segmentation": [
  655. {
  656. "name": "--prompt_type",
  657. "type": str,
  658. "help": "Sets the prompt type for open vocabulary segmentation.",
  659. },
  660. {
  661. "name": "--prompt",
  662. "type": custom_type(List[List[float]]),
  663. "help": "Sets the prompt for open vocabulary segmentation.",
  664. },
  665. ],
  666. "3d_bev_detection": None,
  667. "multilingual_speech_recognition": None,
  668. }