pipeline.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  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 typing import Any, Dict, List, Optional, Tuple, Union
  15. import numpy as np
  16. from ....utils import logging
  17. from ....utils.deps import pipeline_requires_extra
  18. from ...common.batch_sampler import ImageBatchSampler
  19. from ...common.reader import ReadImage
  20. from ...models.object_detection.result import DetResult
  21. from ...utils.benchmark import benchmark
  22. from ...utils.hpi import HPIConfig
  23. from ...utils.pp_option import PaddlePredictorOption
  24. from .._parallel import AutoParallelImageSimpleInferencePipeline
  25. from ..base import BasePipeline
  26. from ..components import CropByBoxes
  27. from ..ocr.result import OCRResult
  28. from .result import LayoutParsingResult
  29. from .utils import get_sub_regions_ocr_res, sorted_layout_boxes
  30. @benchmark.time_methods
  31. class _LayoutParsingPipeline(BasePipeline):
  32. """Layout Parsing Pipeline"""
  33. def __init__(
  34. self,
  35. config: Dict,
  36. device: str = None,
  37. pp_option: PaddlePredictorOption = None,
  38. use_hpip: bool = False,
  39. hpi_config: Optional[Union[Dict[str, Any], HPIConfig]] = None,
  40. ) -> None:
  41. """Initializes the layout parsing pipeline.
  42. Args:
  43. config (Dict): Configuration dictionary containing various settings.
  44. device (str, optional): Device to run the predictions on. Defaults to None.
  45. pp_option (PaddlePredictorOption, optional): PaddlePredictor options. Defaults to None.
  46. use_hpip (bool, optional): Whether to use the high-performance
  47. inference plugin (HPIP) by default. Defaults to False.
  48. hpi_config (Optional[Union[Dict[str, Any], HPIConfig]], optional):
  49. The default high-performance inference configuration dictionary.
  50. Defaults to None.
  51. """
  52. super().__init__(
  53. device=device, pp_option=pp_option, use_hpip=use_hpip, hpi_config=hpi_config
  54. )
  55. self.inintial_predictor(config)
  56. self.batch_sampler = ImageBatchSampler(batch_size=1)
  57. self.img_reader = ReadImage(format="BGR")
  58. self._crop_by_boxes = CropByBoxes()
  59. def inintial_predictor(self, config: Dict) -> None:
  60. """Initializes the predictor based on the provided configuration.
  61. Args:
  62. config (Dict): A dictionary containing the configuration for the predictor.
  63. Returns:
  64. None
  65. """
  66. self.use_doc_preprocessor = config.get("use_doc_preprocessor", True)
  67. self.use_table_recognition = config.get("use_table_recognition", True)
  68. self.use_seal_recognition = config.get("use_seal_recognition", True)
  69. self.use_formula_recognition = config.get("use_formula_recognition", True)
  70. if self.use_doc_preprocessor:
  71. doc_preprocessor_config = config.get("SubPipelines", {}).get(
  72. "DocPreprocessor",
  73. {
  74. "pipeline_config_error": "config error for doc_preprocessor_pipeline!"
  75. },
  76. )
  77. self.doc_preprocessor_pipeline = self.create_pipeline(
  78. doc_preprocessor_config
  79. )
  80. layout_det_config = config.get("SubModules", {}).get(
  81. "LayoutDetection",
  82. {"model_config_error": "config error for layout_det_model!"},
  83. )
  84. layout_kwargs = {}
  85. if (threshold := layout_det_config.get("threshold", None)) is not None:
  86. layout_kwargs["threshold"] = threshold
  87. if (layout_nms := layout_det_config.get("layout_nms", None)) is not None:
  88. layout_kwargs["layout_nms"] = layout_nms
  89. if (
  90. layout_unclip_ratio := layout_det_config.get("layout_unclip_ratio", None)
  91. ) is not None:
  92. layout_kwargs["layout_unclip_ratio"] = layout_unclip_ratio
  93. if (
  94. layout_merge_bboxes_mode := layout_det_config.get(
  95. "layout_merge_bboxes_mode", None
  96. )
  97. ) is not None:
  98. layout_kwargs["layout_merge_bboxes_mode"] = layout_merge_bboxes_mode
  99. self.layout_det_model = self.create_model(layout_det_config, **layout_kwargs)
  100. general_ocr_config = config.get("SubPipelines", {}).get(
  101. "GeneralOCR",
  102. {"pipeline_config_error": "config error for general_ocr_pipeline!"},
  103. )
  104. self.general_ocr_pipeline = self.create_pipeline(general_ocr_config)
  105. if self.use_seal_recognition:
  106. seal_recognition_config = config.get("SubPipelines", {}).get(
  107. "SealRecognition",
  108. {
  109. "pipeline_config_error": "config error for seal_recognition_pipeline!"
  110. },
  111. )
  112. self.seal_recognition_pipeline = self.create_pipeline(
  113. seal_recognition_config
  114. )
  115. if self.use_table_recognition:
  116. table_recognition_config = config.get("SubPipelines", {}).get(
  117. "TableRecognition",
  118. {
  119. "pipeline_config_error": "config error for table_recognition_pipeline!"
  120. },
  121. )
  122. self.table_recognition_pipeline = self.create_pipeline(
  123. table_recognition_config
  124. )
  125. if self.use_formula_recognition:
  126. formula_recognition_config = config.get("SubPipelines", {}).get(
  127. "FormulaRecognition",
  128. {
  129. "pipeline_config_error": "config error for formula_recognition_pipeline!"
  130. },
  131. )
  132. self.formula_recognition_pipeline = self.create_pipeline(
  133. formula_recognition_config
  134. )
  135. return
  136. def get_layout_parsing_res(
  137. self,
  138. image: list,
  139. layout_det_res: DetResult,
  140. overall_ocr_res: OCRResult,
  141. table_res_list: list,
  142. seal_res_list: list,
  143. formula_res_list: list,
  144. text_det_limit_side_len: Optional[int] = None,
  145. text_det_limit_type: Optional[str] = None,
  146. text_det_thresh: Optional[float] = None,
  147. text_det_box_thresh: Optional[float] = None,
  148. text_det_unclip_ratio: Optional[float] = None,
  149. text_rec_score_thresh: Optional[float] = None,
  150. ) -> list:
  151. """
  152. Retrieves the layout parsing result based on the layout detection result, OCR result, and other recognition results.
  153. Args:
  154. image (list): The input image.
  155. layout_det_res (DetResult): The detection result containing the layout information of the document.
  156. overall_ocr_res (OCRResult): The overall OCR result containing text information.
  157. table_res_list (list): A list of table recognition results.
  158. seal_res_list (list): A list of seal recognition results.
  159. formula_res_list (list): A list of formula recognition results.
  160. text_det_limit_side_len (Optional[int], optional): The maximum side length of the text detection region. Defaults to None.
  161. text_det_limit_type (Optional[str], optional): The type of limit for the text detection region. Defaults to None.
  162. text_det_thresh (Optional[float], optional): The confidence threshold for text detection. Defaults to None.
  163. text_det_box_thresh (Optional[float], optional): The confidence threshold for text detection bounding boxes. Defaults to None
  164. text_det_unclip_ratio (Optional[float], optional): The unclip ratio for text detection. Defaults to None.
  165. text_rec_score_thresh (Optional[float], optional): The score threshold for text recognition. Defaults to None.
  166. Returns:
  167. list: A list of dictionaries representing the layout parsing result.
  168. """
  169. layout_parsing_res = []
  170. matched_ocr_dict = {}
  171. formula_index = 0
  172. table_index = 0
  173. seal_index = 0
  174. image = np.array(image)
  175. object_boxes = []
  176. for object_box_idx, box_info in enumerate(layout_det_res["boxes"]):
  177. single_box_res = {}
  178. box = box_info["coordinate"]
  179. label = box_info["label"].lower()
  180. single_box_res["block_bbox"] = box
  181. single_box_res["block_label"] = label
  182. single_box_res["block_content"] = ""
  183. object_boxes.append(box)
  184. if label == "formula":
  185. if len(formula_res_list) > 0:
  186. assert (
  187. len(formula_res_list) > formula_index
  188. ), f"The number of \
  189. formula regions of layout parsing pipeline \
  190. and formula recognition pipeline are different!"
  191. single_box_res["block_content"] = formula_res_list[formula_index][
  192. "rec_formula"
  193. ]
  194. formula_index += 1
  195. elif label == "table":
  196. if len(table_res_list) > 0:
  197. assert (
  198. len(table_res_list) > table_index
  199. ), f"The number of \
  200. table regions of layout parsing pipeline \
  201. and table recognition pipeline are different!"
  202. single_box_res["block_content"] = table_res_list[table_index][
  203. "pred_html"
  204. ]
  205. table_index += 1
  206. elif label == "seal":
  207. if len(seal_res_list) > 0:
  208. assert (
  209. len(seal_res_list) > seal_index
  210. ), f"The number of \
  211. seal regions of layout parsing pipeline \
  212. and seal recognition pipeline are different!"
  213. single_box_res["block_content"] = ", ".join(
  214. seal_res_list[seal_index]["rec_texts"]
  215. )
  216. seal_index += 1
  217. else:
  218. ocr_res_in_box, matched_idxes = get_sub_regions_ocr_res(
  219. overall_ocr_res, [box], return_match_idx=True
  220. )
  221. for matched_idx in matched_idxes:
  222. if matched_ocr_dict.get(matched_idx, None) is None:
  223. matched_ocr_dict[matched_idx] = [object_box_idx]
  224. else:
  225. matched_ocr_dict[matched_idx].append(object_box_idx)
  226. single_box_res["block_content"] = "\n".join(ocr_res_in_box["rec_texts"])
  227. layout_parsing_res.append(single_box_res)
  228. for layout_box_ids in matched_ocr_dict.values():
  229. # one ocr is matched to multiple layout boxes, split the text into multiple lines
  230. if len(layout_box_ids) > 1:
  231. for idx in layout_box_ids:
  232. wht_im = np.ones(image.shape, dtype=image.dtype) * 255
  233. box = layout_parsing_res[idx]["block_bbox"]
  234. x1, y1, x2, y2 = [int(i) for i in box]
  235. wht_im[y1:y2, x1:x2, :] = image[y1:y2, x1:x2, :]
  236. sub_ocr_res = list(
  237. self.general_ocr_pipeline(
  238. wht_im,
  239. text_det_limit_side_len=text_det_limit_side_len,
  240. text_det_limit_type=text_det_limit_type,
  241. text_det_thresh=text_det_thresh,
  242. text_det_box_thresh=text_det_box_thresh,
  243. text_det_unclip_ratio=text_det_unclip_ratio,
  244. text_rec_score_thresh=text_rec_score_thresh,
  245. )
  246. )[0]
  247. layout_parsing_res[idx]["block_content"] = "\n".join(
  248. sub_ocr_res["rec_texts"]
  249. )
  250. ocr_without_layout_boxes = get_sub_regions_ocr_res(
  251. overall_ocr_res, object_boxes, flag_within=False
  252. )
  253. for ocr_rec_box, ocr_rec_text in zip(
  254. ocr_without_layout_boxes["rec_boxes"], ocr_without_layout_boxes["rec_texts"]
  255. ):
  256. single_box_res = {}
  257. single_box_res["block_bbox"] = ocr_rec_box
  258. single_box_res["block_label"] = "other_text"
  259. single_box_res["block_content"] = ocr_rec_text
  260. layout_parsing_res.append(single_box_res)
  261. layout_parsing_res = sorted_layout_boxes(layout_parsing_res, w=image.shape[1])
  262. return layout_parsing_res
  263. def check_model_settings_valid(self, input_params: Dict) -> bool:
  264. """
  265. Check if the input parameters are valid based on the initialized models.
  266. Args:
  267. input_params (Dict): A dictionary containing input parameters.
  268. Returns:
  269. bool: True if all required models are initialized according to input parameters, False otherwise.
  270. """
  271. if input_params["use_doc_preprocessor"] and not self.use_doc_preprocessor:
  272. logging.error(
  273. "Set use_doc_preprocessor, but the models for doc preprocessor are not initialized."
  274. )
  275. return False
  276. if input_params["use_seal_recognition"] and not self.use_seal_recognition:
  277. logging.error(
  278. "Set use_seal_recognition, but the models for seal recognition are not initialized."
  279. )
  280. return False
  281. if input_params["use_table_recognition"] and not self.use_table_recognition:
  282. logging.error(
  283. "Set use_table_recognition, but the models for table recognition are not initialized."
  284. )
  285. return False
  286. return True
  287. def get_model_settings(
  288. self,
  289. use_doc_orientation_classify: Optional[bool],
  290. use_doc_unwarping: Optional[bool],
  291. use_seal_recognition: Optional[bool],
  292. use_table_recognition: Optional[bool],
  293. use_formula_recognition: Optional[bool],
  294. ) -> dict:
  295. """
  296. Get the model settings based on the provided parameters or default values.
  297. Args:
  298. use_doc_orientation_classify (Optional[bool]): Whether to use document orientation classification.
  299. use_doc_unwarping (Optional[bool]): Whether to use document unwarping.
  300. use_seal_recognition (Optional[bool]): Whether to use seal recognition.
  301. use_table_recognition (Optional[bool]): Whether to use table recognition.
  302. Returns:
  303. dict: A dictionary containing the model settings.
  304. """
  305. if use_doc_orientation_classify is None and use_doc_unwarping is None:
  306. use_doc_preprocessor = self.use_doc_preprocessor
  307. else:
  308. if use_doc_orientation_classify is True or use_doc_unwarping is True:
  309. use_doc_preprocessor = True
  310. else:
  311. use_doc_preprocessor = False
  312. if use_seal_recognition is None:
  313. use_seal_recognition = self.use_seal_recognition
  314. if use_table_recognition is None:
  315. use_table_recognition = self.use_table_recognition
  316. if use_formula_recognition is None:
  317. use_formula_recognition = self.use_formula_recognition
  318. return dict(
  319. use_doc_preprocessor=use_doc_preprocessor,
  320. use_seal_recognition=use_seal_recognition,
  321. use_table_recognition=use_table_recognition,
  322. use_formula_recognition=use_formula_recognition,
  323. )
  324. def predict(
  325. self,
  326. input: Union[str, List[str], np.ndarray, List[np.ndarray]],
  327. use_doc_orientation_classify: Optional[bool] = None,
  328. use_doc_unwarping: Optional[bool] = None,
  329. use_textline_orientation: Optional[bool] = None,
  330. use_seal_recognition: Optional[bool] = None,
  331. use_table_recognition: Optional[bool] = None,
  332. use_formula_recognition: Optional[bool] = None,
  333. layout_threshold: Optional[Union[float, dict]] = None,
  334. layout_nms: Optional[bool] = None,
  335. layout_unclip_ratio: Optional[Union[float, Tuple[float, float], dict]] = None,
  336. layout_merge_bboxes_mode: Optional[str] = None,
  337. text_det_limit_side_len: Optional[int] = None,
  338. text_det_limit_type: Optional[str] = None,
  339. text_det_thresh: Optional[float] = None,
  340. text_det_box_thresh: Optional[float] = None,
  341. text_det_unclip_ratio: Optional[float] = None,
  342. text_rec_score_thresh: Optional[float] = None,
  343. seal_det_limit_side_len: Optional[int] = None,
  344. seal_det_limit_type: Optional[str] = None,
  345. seal_det_thresh: Optional[float] = None,
  346. seal_det_box_thresh: Optional[float] = None,
  347. seal_det_unclip_ratio: Optional[float] = None,
  348. seal_rec_score_thresh: Optional[float] = None,
  349. **kwargs,
  350. ) -> LayoutParsingResult:
  351. """
  352. This function predicts the layout parsing result for the given input.
  353. Args:
  354. input (Union[str, list[str], np.ndarray, list[np.ndarray]]): The input image(s) or pdf(s) to be processed.
  355. use_doc_orientation_classify (Optional[bool]): Whether to use document orientation classification.
  356. use_doc_unwarping (Optional[bool]): Whether to use document unwarping.
  357. use_textline_orientation (Optional[bool]): Whether to use textline orientation prediction.
  358. use_seal_recognition (Optional[bool]): Whether to use seal recognition.
  359. use_table_recognition (Optional[bool]): Whether to use table recognition.
  360. use_formula_recognition (Optional[bool]): Whether to use formula recognition.
  361. layout_threshold (Optional[float]): The threshold value to filter out low-confidence predictions. Default is None.
  362. layout_nms (bool, optional): Whether to use layout-aware NMS. Defaults to False.
  363. layout_unclip_ratio (Optional[Union[float, Tuple[float, float]]], optional): The ratio of unclipping the bounding box.
  364. Defaults to None.
  365. If it's a single number, then both width and height are used.
  366. If it's a tuple of two numbers, then they are used separately for width and height respectively.
  367. If it's None, then no unclipping will be performed.
  368. layout_merge_bboxes_mode (Optional[str], optional): The mode for merging bounding boxes. Defaults to None.
  369. text_det_limit_side_len (Optional[int]): Maximum side length for text detection.
  370. text_det_limit_type (Optional[str]): Type of limit to apply for text detection.
  371. text_det_thresh (Optional[float]): Threshold for text detection.
  372. text_det_box_thresh (Optional[float]): Threshold for text detection boxes.
  373. text_det_unclip_ratio (Optional[float]): Ratio for unclipping text detection boxes.
  374. text_rec_score_thresh (Optional[float]): Score threshold for text recognition.
  375. seal_det_limit_side_len (Optional[int]): Maximum side length for seal detection.
  376. seal_det_limit_type (Optional[str]): Type of limit to apply for seal detection.
  377. seal_det_thresh (Optional[float]): Threshold for seal detection.
  378. seal_det_box_thresh (Optional[float]): Threshold for seal detection boxes.
  379. seal_det_unclip_ratio (Optional[float]): Ratio for unclipping seal detection boxes.
  380. seal_rec_score_thresh (Optional[float]): Score threshold for seal recognition.
  381. **kwargs: Additional keyword arguments.
  382. Returns:
  383. LayoutParsingResult: The predicted layout parsing result.
  384. """
  385. model_settings = self.get_model_settings(
  386. use_doc_orientation_classify,
  387. use_doc_unwarping,
  388. use_seal_recognition,
  389. use_table_recognition,
  390. use_formula_recognition,
  391. )
  392. if not self.check_model_settings_valid(model_settings):
  393. yield {"error": "the input params for model settings are invalid!"}
  394. for img_id, batch_data in enumerate(self.batch_sampler(input)):
  395. image_array = self.img_reader(batch_data.instances)[0]
  396. if model_settings["use_doc_preprocessor"]:
  397. doc_preprocessor_res = list(
  398. self.doc_preprocessor_pipeline(
  399. image_array,
  400. use_doc_orientation_classify=use_doc_orientation_classify,
  401. use_doc_unwarping=use_doc_unwarping,
  402. )
  403. )[0]
  404. else:
  405. doc_preprocessor_res = {"output_img": image_array}
  406. doc_preprocessor_image = doc_preprocessor_res["output_img"]
  407. layout_det_res = list(
  408. self.layout_det_model(
  409. doc_preprocessor_image,
  410. threshold=layout_threshold,
  411. layout_nms=layout_nms,
  412. layout_unclip_ratio=layout_unclip_ratio,
  413. layout_merge_bboxes_mode=layout_merge_bboxes_mode,
  414. )
  415. )[0]
  416. overall_ocr_res = list(
  417. self.general_ocr_pipeline(
  418. doc_preprocessor_image,
  419. use_textline_orientation=use_textline_orientation,
  420. text_det_limit_side_len=text_det_limit_side_len,
  421. text_det_limit_type=text_det_limit_type,
  422. text_det_thresh=text_det_thresh,
  423. text_det_box_thresh=text_det_box_thresh,
  424. text_det_unclip_ratio=text_det_unclip_ratio,
  425. text_rec_score_thresh=text_rec_score_thresh,
  426. )
  427. )[0]
  428. if model_settings["use_table_recognition"]:
  429. table_res_all = list(
  430. self.table_recognition_pipeline(
  431. doc_preprocessor_image,
  432. use_doc_orientation_classify=False,
  433. use_doc_unwarping=False,
  434. use_layout_detection=False,
  435. use_ocr_model=False,
  436. overall_ocr_res=overall_ocr_res,
  437. layout_det_res=layout_det_res,
  438. )
  439. )[0]
  440. table_res_list = table_res_all["table_res_list"]
  441. else:
  442. table_res_list = []
  443. if model_settings["use_seal_recognition"]:
  444. seal_res_all = list(
  445. self.seal_recognition_pipeline(
  446. doc_preprocessor_image,
  447. use_doc_orientation_classify=False,
  448. use_doc_unwarping=False,
  449. use_layout_detection=False,
  450. layout_det_res=layout_det_res,
  451. seal_det_limit_side_len=seal_det_limit_side_len,
  452. seal_det_limit_type=seal_det_limit_type,
  453. seal_det_thresh=seal_det_thresh,
  454. seal_det_box_thresh=seal_det_box_thresh,
  455. seal_det_unclip_ratio=seal_det_unclip_ratio,
  456. seal_rec_score_thresh=seal_rec_score_thresh,
  457. )
  458. )[0]
  459. seal_res_list = seal_res_all["seal_res_list"]
  460. else:
  461. seal_res_list = []
  462. if model_settings["use_formula_recognition"]:
  463. formula_res_all = list(
  464. self.formula_recognition_pipeline(
  465. doc_preprocessor_image,
  466. use_layout_detection=False,
  467. use_doc_orientation_classify=False,
  468. use_doc_unwarping=False,
  469. layout_det_res=layout_det_res,
  470. )
  471. )[0]
  472. formula_res_list = formula_res_all["formula_res_list"]
  473. else:
  474. formula_res_list = []
  475. parsing_res_list = self.get_layout_parsing_res(
  476. doc_preprocessor_image,
  477. layout_det_res=layout_det_res,
  478. overall_ocr_res=overall_ocr_res,
  479. table_res_list=table_res_list,
  480. seal_res_list=seal_res_list,
  481. formula_res_list=formula_res_list,
  482. text_det_limit_side_len=text_det_limit_side_len,
  483. text_det_limit_type=text_det_limit_type,
  484. text_det_thresh=text_det_thresh,
  485. text_det_box_thresh=text_det_box_thresh,
  486. text_det_unclip_ratio=text_det_unclip_ratio,
  487. text_rec_score_thresh=text_rec_score_thresh,
  488. )
  489. single_img_res = {
  490. "input_path": batch_data.input_paths[0],
  491. "page_index": batch_data.page_indexes[0],
  492. "doc_preprocessor_res": doc_preprocessor_res,
  493. "layout_det_res": layout_det_res,
  494. "overall_ocr_res": overall_ocr_res,
  495. "table_res_list": table_res_list,
  496. "seal_res_list": seal_res_list,
  497. "formula_res_list": formula_res_list,
  498. "parsing_res_list": parsing_res_list,
  499. "model_settings": model_settings,
  500. }
  501. yield LayoutParsingResult(single_img_res)
  502. @pipeline_requires_extra("ocr")
  503. class LayoutParsingPipeline(AutoParallelImageSimpleInferencePipeline):
  504. entities = ["layout_parsing"]
  505. @property
  506. def _pipeline_cls(self):
  507. return _LayoutParsingPipeline
  508. def _get_batch_size(self, config):
  509. return 1