Skip to content

Commit 4b9e8ce

Browse files
committed
fix(layout,table): update e2e test
Signed-off-by: Clément Doumouro <[email protected]>
1 parent 7fec51c commit 4b9e8ce

40 files changed

+26064
-23356
lines changed

docling/models/layout_model.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,17 @@ def download_models(
102102
)
103103

104104
def draw_clusters_and_cells_side_by_side(
105-
self,
106-
conv_res,
107-
page,
108-
clusters,
109-
mode_prefix: str,
110-
show: bool = False,
105+
self, conv_res, page, clusters, mode_prefix: str, show: bool = False
111106
):
112107
"""
113108
Draws a page image side by side with clusters filtered into two categories:
114109
- Left: Clusters excluding FORM, KEY_VALUE_REGION, and PICTURE.
115110
- Right: Clusters including FORM, KEY_VALUE_REGION, and PICTURE.
116111
Includes label names and confidence scores for each cluster.
117112
"""
118-
page_image = deepcopy(page.image)
119-
scale_x = page_image.width / page.size.width
120-
scale_y = page_image.height / page.size.height
113+
scale_x = page.image.width / page.size.width
114+
scale_y = page.image.height / page.size.height
115+
121116
# Filter clusters for left and right images
122117
exclude_labels = {
123118
DocItemLabel.FORM,
@@ -127,8 +122,8 @@ def draw_clusters_and_cells_side_by_side(
127122
left_clusters = [c for c in clusters if c.label not in exclude_labels]
128123
right_clusters = [c for c in clusters if c.label in exclude_labels]
129124
# Create a deep copy of the original image for both sides
130-
left_image = page_image
131-
right_image = copy.deepcopy(left_image)
125+
left_image = copy.deepcopy(page.image)
126+
right_image = copy.deepcopy(page.image)
132127

133128
# Draw clusters on both images
134129
draw_clusters(left_image, left_clusters, scale_x, scale_y)
@@ -191,10 +186,7 @@ def __call__(
191186

192187
if settings.debug.visualize_raw_layout:
193188
self.draw_clusters_and_cells_side_by_side(
194-
conv_res,
195-
page,
196-
clusters,
197-
mode_prefix="raw",
189+
conv_res, page, clusters, mode_prefix="raw"
198190
)
199191

200192
# Apply postprocessing
@@ -228,10 +220,7 @@ def __call__(
228220

229221
if settings.debug.visualize_layout:
230222
self.draw_clusters_and_cells_side_by_side(
231-
conv_res,
232-
page,
233-
processed_clusters,
234-
mode_prefix="postprocessed",
223+
conv_res, page, processed_clusters, mode_prefix="postprocessed"
235224
)
236225

237226
yield page

docling/models/ocr_mac_model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ def __call__(
107107
x2 = x1 + w * im_width
108108
y1 = y2 - h * im_height
109109

110-
left = x1 / self.scale
111-
top = y1 / self.scale
112-
right = x2 / self.scale
113-
bottom = y2 / self.scale
110+
left = x1 / self.scale + ocr_rect.l
111+
top = y1 / self.scale + ocr_rect.t
112+
right = x2 / self.scale + ocr_rect.l
113+
bottom = y2 / self.scale + ocr_rect.t
114114

115115
cells.append(
116116
TextCell(

docling/models/table_structure_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def __call__(
260260
)
261261
new_bbox = _rotate_bbox(
262262
new_cell.to_bounding_box(),
263-
orientation=-cells_orientation,
263+
orientation=cells_orientation,
264264
im_size=scaled_page_im.size,
265265
).model_dump()
266266
tokens.append(
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<document>
2-
<subtitle-level-1><location><page_1><loc_33><loc_87><loc_68><loc_91></location>This is a table test</subtitle-level-1>
3-
<paragraph><location><page_1><loc_12><loc_83><loc_61><loc_84></location>The test starts with some random text and then a table image:</paragraph>
4-
<paragraph><location><page_1><loc_45><loc_76><loc_56><loc_77></location>Some column</paragraph>
5-
<paragraph><location><page_1><loc_62><loc_76><loc_78><loc_77></location>Some other column</paragraph>
6-
<paragraph><location><page_1><loc_29><loc_70><loc_37><loc_71></location>Some row</paragraph>
7-
<paragraph><location><page_1><loc_47><loc_70><loc_54><loc_71></location>some cell</paragraph>
8-
<paragraph><location><page_1><loc_65><loc_70><loc_76><loc_71></location>have content</paragraph>
9-
<paragraph><location><page_1><loc_26><loc_64><loc_39><loc_65></location>Some other row</paragraph>
10-
<paragraph><location><page_1><loc_46><loc_64><loc_55><loc_65></location>other don't</paragraph>
2+
<table>
3+
<location><page_1><loc_9><loc_45><loc_70><loc_86></location>
4+
<row_0><col_0><col_header>Vertically merged</col_0><col_1><col_header>Other merged column</col_1><col_2><col_header>Yet another column</col_2></row_0>
5+
<row_1><col_0><body>value</col_0><col_1><body>Some other value</col_1><col_2><body>Yet another value</col_2></row_1>
6+
<row_2><col_0><body>value</col_0><col_1><body>Some other value</col_1><col_2><body>Yet another value</col_2></row_2>
7+
</table>
118
</document>

0 commit comments

Comments
 (0)