pipeline_arguments.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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": None,
  138. "table_recognition_v2": None,
  139. "seal_recognition": [
  140. {
  141. "name": "--use_doc_orientation_classify",
  142. "type": bool,
  143. "help": "Determines whether to use document preprocessing",
  144. },
  145. {
  146. "name": "--use_doc_unwarping",
  147. "type": bool,
  148. "help": "Determines whether to use document unwarping",
  149. },
  150. {
  151. "name": "--use_layout_detection",
  152. "type": bool,
  153. "help": "Determines whether to use document layout detection",
  154. },
  155. {
  156. "name": "--layout_threshold",
  157. "type": float,
  158. "help": "Determines confidence threshold for layout detection",
  159. },
  160. {
  161. "name": "--layout_nms",
  162. "type": bool,
  163. "help": "Determines whether to use non maximum suppression",
  164. },
  165. {
  166. "name": "--layout_unclip_ratio",
  167. "type": float,
  168. "help": "Determines unclip ratio for layout detection boxes",
  169. },
  170. {
  171. "name": "--layout_merge_bboxes_mode",
  172. "type": str,
  173. "help": "Determines merge mode for layout detection bboxes, 'union', 'large' or 'small'",
  174. },
  175. {
  176. "name": "--seal_det_limit_side_len",
  177. "type": int,
  178. "help": "Sets the side length limit for text detection.",
  179. },
  180. {
  181. "name": "--seal_det_limit_type",
  182. "type": str,
  183. "help": "Sets the limit type for text detection, 'min', 'max'.",
  184. },
  185. {
  186. "name": "--seal_det_thresh",
  187. "type": float,
  188. "help": "Sets the threshold for text detection.",
  189. },
  190. {
  191. "name": "--seal_det_box_thresh",
  192. "type": float,
  193. "help": "Sets the box threshold for text detection.",
  194. },
  195. {
  196. "name": "--seal_det_unclip_ratio",
  197. "type": float,
  198. "help": "Sets the unclip ratio for text detection.",
  199. },
  200. {
  201. "name": "--seal_rec_score_thresh",
  202. "type": float,
  203. "help": "Sets the score threshold for text recognition.",
  204. },
  205. ],
  206. "layout_parsing": [
  207. {
  208. "name": "--use_doc_orientation_classify",
  209. "type": bool,
  210. "help": "Determines whether to use document orientation classification",
  211. },
  212. {
  213. "name": "--use_doc_unwarping",
  214. "type": bool,
  215. "help": "Determines whether to use document unwarping",
  216. },
  217. {
  218. "name": "--use_general_ocr",
  219. "type": bool,
  220. "help": "Determines whether to use general ocr",
  221. },
  222. {
  223. "name": "--use_textline_orientation",
  224. "type": bool,
  225. "help": "Determines whether to consider text line orientation",
  226. },
  227. {
  228. "name": "--use_seal_recognition",
  229. "type": bool,
  230. "help": "Determines whether to use seal recognition",
  231. },
  232. {
  233. "name": "--use_table_recognition",
  234. "type": bool,
  235. "help": "Determines whether to use table recognition",
  236. },
  237. {
  238. "name": "--use_formula_recognition",
  239. "type": bool,
  240. "help": "Determines whether to use formula recognition",
  241. },
  242. {
  243. "name": "--layout_threshold",
  244. "type": float,
  245. "help": "Determines confidence threshold for layout detection",
  246. },
  247. {
  248. "name": "--layout_nms",
  249. "type": bool,
  250. "help": "Determines whether to use non maximum suppression",
  251. },
  252. {
  253. "name": "--layout_unclip_ratio",
  254. "type": float,
  255. "help": "Determines unclip ratio for layout detection boxes",
  256. },
  257. {
  258. "name": "--layout_merge_bboxes_mode",
  259. "type": str,
  260. "help": "Determines merge mode for layout detection bboxes, 'union', 'large' or 'small'",
  261. },
  262. {
  263. "name": "--seal_det_limit_side_len",
  264. "type": int,
  265. "help": "Sets the side length limit for text detection.",
  266. },
  267. {
  268. "name": "--seal_det_limit_type",
  269. "type": str,
  270. "help": "Sets the limit type for text detection, 'min', 'max'.",
  271. },
  272. {
  273. "name": "--seal_det_thresh",
  274. "type": float,
  275. "help": "Sets the threshold for text detection.",
  276. },
  277. {
  278. "name": "--seal_det_box_thresh",
  279. "type": float,
  280. "help": "Sets the box threshold for text detection.",
  281. },
  282. {
  283. "name": "--seal_det_unclip_ratio",
  284. "type": float,
  285. "help": "Sets the unclip ratio for text detection.",
  286. },
  287. {
  288. "name": "--seal_rec_score_thresh",
  289. "type": float,
  290. "help": "Sets the score threshold for text recognition.",
  291. },
  292. {
  293. "name": "--text_det_limit_side_len",
  294. "type": int,
  295. "help": "Sets the side length limit for text detection.",
  296. },
  297. {
  298. "name": "--text_det_limit_type",
  299. "type": str,
  300. "help": "Sets the limit type for text detection.",
  301. },
  302. {
  303. "name": "--text_det_thresh",
  304. "type": float,
  305. "help": "Sets the threshold for text detection.",
  306. },
  307. {
  308. "name": "--text_det_box_thresh",
  309. "type": float,
  310. "help": "Sets the box threshold for text detection.",
  311. },
  312. {
  313. "name": "--text_det_unclip_ratio",
  314. "type": float,
  315. "help": "Sets the unclip ratio for text detection.",
  316. },
  317. {
  318. "name": "--text_rec_score_thresh",
  319. "type": float,
  320. "help": "Sets the score threshold for text recognition.",
  321. },
  322. ],
  323. "layout_parsing_v2": [
  324. {
  325. "name": "--use_doc_orientation_classify",
  326. "type": bool,
  327. "help": "Determines whether to use document orientation classification",
  328. },
  329. {
  330. "name": "--use_doc_unwarping",
  331. "type": bool,
  332. "help": "Determines whether to use document unwarping",
  333. },
  334. {
  335. "name": "--use_general_ocr",
  336. "type": bool,
  337. "help": "Determines whether to use general ocr",
  338. },
  339. {
  340. "name": "--use_textline_orientation",
  341. "type": bool,
  342. "help": "Determines whether to consider text line orientation",
  343. },
  344. {
  345. "name": "--use_seal_recognition",
  346. "type": bool,
  347. "help": "Determines whether to use seal recognition",
  348. },
  349. {
  350. "name": "--use_table_recognition",
  351. "type": bool,
  352. "help": "Determines whether to use table recognition",
  353. },
  354. {
  355. "name": "--use_formula_recognition",
  356. "type": bool,
  357. "help": "Determines whether to use formula recognition",
  358. },
  359. {
  360. "name": "--layout_threshold",
  361. "type": float,
  362. "help": "Determines confidence threshold for layout detection",
  363. },
  364. {
  365. "name": "--layout_nms",
  366. "type": bool,
  367. "help": "Determines whether to use non maximum suppression",
  368. },
  369. {
  370. "name": "--layout_unclip_ratio",
  371. "type": float,
  372. "help": "Determines unclip ratio for layout detection boxes",
  373. },
  374. {
  375. "name": "--layout_merge_bboxes_mode",
  376. "type": str,
  377. "help": "Determines merge mode for layout detection bboxes, 'union', 'large' or 'small'",
  378. },
  379. {
  380. "name": "--seal_det_limit_side_len",
  381. "type": int,
  382. "help": "Sets the side length limit for text detection.",
  383. },
  384. {
  385. "name": "--seal_det_limit_type",
  386. "type": str,
  387. "help": "Sets the limit type for text detection, 'min', 'max'.",
  388. },
  389. {
  390. "name": "--seal_det_thresh",
  391. "type": float,
  392. "help": "Sets the threshold for text detection.",
  393. },
  394. {
  395. "name": "--seal_det_box_thresh",
  396. "type": float,
  397. "help": "Sets the box threshold for text detection.",
  398. },
  399. {
  400. "name": "--seal_det_unclip_ratio",
  401. "type": float,
  402. "help": "Sets the unclip ratio for text detection.",
  403. },
  404. {
  405. "name": "--seal_rec_score_thresh",
  406. "type": float,
  407. "help": "Sets the score threshold for text recognition.",
  408. },
  409. {
  410. "name": "--text_det_limit_side_len",
  411. "type": int,
  412. "help": "Sets the side length limit for text detection.",
  413. },
  414. {
  415. "name": "--text_det_limit_type",
  416. "type": str,
  417. "help": "Sets the limit type for text detection.",
  418. },
  419. {
  420. "name": "--text_det_thresh",
  421. "type": float,
  422. "help": "Sets the threshold for text detection.",
  423. },
  424. {
  425. "name": "--text_det_box_thresh",
  426. "type": float,
  427. "help": "Sets the box threshold for text detection.",
  428. },
  429. {
  430. "name": "--text_det_unclip_ratio",
  431. "type": float,
  432. "help": "Sets the unclip ratio for text detection.",
  433. },
  434. {
  435. "name": "--text_rec_score_thresh",
  436. "type": float,
  437. "help": "Sets the score threshold for text recognition.",
  438. },
  439. ],
  440. "ts_forecast": None,
  441. "ts_anomaly_detection": None,
  442. "ts_classification": None,
  443. "formula_recognition": [
  444. {
  445. "name": "--use_layout_detection",
  446. "type": bool,
  447. "help": "Determines whether to use layout detection",
  448. },
  449. {
  450. "name": "--use_doc_orientation_classify",
  451. "type": bool,
  452. "help": "Determines whether to use document orientation classification",
  453. },
  454. {
  455. "name": "--use_doc_unwarping",
  456. "type": bool,
  457. "help": "Determines whether to use document unwarping",
  458. },
  459. {
  460. "name": "--layout_threshold",
  461. "type": float,
  462. "help": "Sets the layout threshold for layout detection.",
  463. },
  464. {
  465. "name": "--layout_nms",
  466. "type": bool,
  467. "help": "Determines whether to use layout nms",
  468. },
  469. {
  470. "name": "--layout_unclip_ratio",
  471. "type": float,
  472. "help": "Sets the layout unclip ratio for layout detection.",
  473. },
  474. {
  475. "name": "--layout_merge_bboxes_mode",
  476. "type": str,
  477. "help": "Sets the layout merge bboxes mode for layout detection.",
  478. },
  479. ],
  480. "instance_segmentation": [
  481. {
  482. "name": "--threshold",
  483. "type": custom_type(Optional[float]),
  484. "help": "Sets the threshold for instance segmentation.",
  485. },
  486. ],
  487. "semantic_segmentation": [
  488. {
  489. "name": "--target_size",
  490. "type": custom_type(Optional[Union[int, Tuple[int, int], Literal[-1]]]),
  491. "help": "Sets the inference image resolution for semantic segmentation.",
  492. },
  493. ],
  494. "small_object_detection": [
  495. {
  496. "name": "--threshold",
  497. "type": custom_type(Optional[Union[float, dict[int, float]]]),
  498. "help": "Sets the threshold for small object detection.",
  499. },
  500. ],
  501. "anomaly_detection": None,
  502. "video_classification": [
  503. {
  504. "name": "--topk",
  505. "type": int,
  506. "help": "Sets the Top-K value for video classification.",
  507. },
  508. ],
  509. "video_detection": [
  510. {
  511. "name": "--nms_thresh",
  512. "type": float,
  513. "help": "Sets the NMS threshold for video detection.",
  514. },
  515. {
  516. "name": "--score_thresh",
  517. "type": float,
  518. "help": "Sets the confidence threshold for video detection.",
  519. },
  520. ],
  521. "doc_preprocessor": [
  522. {
  523. "name": "--use_doc_orientation_classify",
  524. "type": bool,
  525. "help": "Determines whether to use document orientation classification.",
  526. },
  527. {
  528. "name": "--use_doc_unwarping",
  529. "type": bool,
  530. "help": "Determines whether to use document unwarping.",
  531. },
  532. ],
  533. "rotated_object_detection": [
  534. {
  535. "name": "--threshold",
  536. "type": custom_type(Optional[Union[float, dict[int, float]]]),
  537. "help": "Sets the threshold for rotated object detection.",
  538. },
  539. ],
  540. "open_vocabulary_detection": [
  541. {
  542. "name": "--thresholds",
  543. "type": custom_type(dict[str, float]),
  544. "help": "Sets the thresholds for open vocabulary detection.",
  545. },
  546. {
  547. "name": "--prompt",
  548. "type": str,
  549. "help": "Sets the prompt for open vocabulary detection.",
  550. },
  551. ],
  552. "open_vocabulary_segmentation": [
  553. {
  554. "name": "--prompt_type",
  555. "type": str,
  556. "help": "Sets the prompt type for open vocabulary segmentation.",
  557. },
  558. {
  559. "name": "--prompt",
  560. "type": custom_type(list[list[float]]),
  561. "help": "Sets the prompt for open vocabulary segmentation.",
  562. },
  563. ],
  564. "3d_bev_detection": None,
  565. }