pipeline.py 26 KB

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