pipeline.py 26 KB

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