pipeline_arguments.py 18 KB

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