Skip to content

Commit 8252abf

Browse files
changdazhouTingquanGao
authored andcommitted
fix bug for doc_title
1 parent ee56bac commit 8252abf

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

paddlex/configs/pipelines/PP-StructureV3.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ SubModules:
6262
21: [1.0, 1.0] # footer_image
6363
22: [1.0, 1.0] # aside_text
6464
layout_merge_bboxes_mode:
65-
0: "union" # paragraph_title
65+
0: "large" # paragraph_title
6666
1: "large" # image
6767
2: "union" # text
6868
3: "union" # number

paddlex/inference/pipelines/layout_parsing/utils.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,21 +575,32 @@ def get_single_block_parsing_res(
575575
single_block_layout_parsing_res = []
576576
input_img = overall_ocr_res["doc_preprocessor_res"]["output_img"]
577577
seal_index = 0
578+
with_doc_title = False
579+
max_block_area = 0.0
580+
paragraph_title_indexs = []
578581

579582
layout_det_res_list, _ = _remove_overlap_blocks(
580583
deepcopy(layout_det_res["boxes"]),
581584
threshold=0.5,
582585
smaller=True,
583586
)
584587

585-
for box_info in layout_det_res_list:
588+
for box_idx, box_info in enumerate(layout_det_res_list):
586589
block_bbox = box_info["coordinate"]
587590
label = box_info["label"]
588591
rec_res = {"boxes": [], "rec_texts": [], "rec_labels": [], "flag": False}
589592
seg_start_coordinate = float("inf")
590593
seg_end_coordinate = float("-inf")
591594
num_of_lines = 1
592595

596+
if label == "doc_title":
597+
with_doc_title = True
598+
elif label == "paragraph_title":
599+
paragraph_title_indexs.append(box_idx)
600+
601+
block_area = (block_bbox[2] - block_bbox[0]) * (block_bbox[3] - block_bbox[1])
602+
max_block_area = max(max_block_area, block_area)
603+
593604
if label == "table":
594605
for table_res in table_res_list:
595606
if len(table_res["cell_box_list"]) == 0:
@@ -679,9 +690,22 @@ def get_single_block_parsing_res(
679690
"seg_start_coordinate": seg_start_coordinate,
680691
"seg_end_coordinate": seg_end_coordinate,
681692
"num_of_lines": num_of_lines,
693+
"block_area": block_area,
682694
},
683695
)
684696

697+
if (
698+
not with_doc_title
699+
and len(paragraph_title_indexs) == 1
700+
and single_block_layout_parsing_res[paragraph_title_indexs[0]].get(
701+
"block_area", 0
702+
)
703+
> max_block_area * 0.3
704+
):
705+
single_block_layout_parsing_res[paragraph_title_indexs[0]][
706+
"block_label"
707+
] = "doc_title"
708+
685709
if len(layout_det_res_list) == 0:
686710
for ocr_rec_box, ocr_rec_text in zip(
687711
overall_ocr_res["rec_boxes"], overall_ocr_res["rec_texts"]

0 commit comments

Comments
 (0)