Skip to content

Commit 0f9e607

Browse files
committed
fix(layout,table): perform orientation detection at the table level
Signed-off-by: Clément Doumouro <[email protected]>
1 parent 7183dc6 commit 0f9e607

24 files changed

+29998
-2887
lines changed

docling/models/table_structure_model.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -276,51 +276,51 @@ def __call__(
276276
)
277277
page_input["tokens"] = tokens
278278

279-
tf_output = self.tf_predictor.multi_table_predict(
280-
page_input, [tbl_box], do_matching=self.do_cell_matching
281-
)
282-
table_out = tf_output[0]
283-
table_cells = []
284-
for element in table_out["tf_responses"]:
285-
if not self.do_cell_matching:
286-
the_bbox = BoundingBox.model_validate(
287-
element["bbox"]
288-
).scaled(1 / self.scale)
289-
text_piece = page._backend.get_text_in_rect(the_bbox)
290-
element["bbox"]["token"] = text_piece
291-
element["bbox"] = _rotate_bbox(
292-
BoundingBox.model_validate(element["bbox"]),
293-
orientation=table_orientation,
294-
im_size=scaled_page_im.size,
295-
).model_dump()
296-
tc = TableCell.model_validate(element)
297-
if tc.bbox is not None:
298-
tc.bbox = tc.bbox.scaled(1 / self.scale)
299-
table_cells.append(tc)
300-
301-
assert "predict_details" in table_out
302-
303-
# Retrieving cols/rows, after post processing:
304-
num_rows = table_out["predict_details"].get("num_rows", 0)
305-
num_cols = table_out["predict_details"].get("num_cols", 0)
306-
otsl_seq = (
307-
table_out["predict_details"]
308-
.get("prediction", {})
309-
.get("rs_seq", [])
310-
)
279+
tf_output = self.tf_predictor.multi_table_predict(
280+
page_input, [tbl_box], do_matching=self.do_cell_matching
281+
)
282+
table_out = tf_output[0]
283+
table_cells = []
284+
for element in table_out["tf_responses"]:
285+
if not self.do_cell_matching:
286+
the_bbox = BoundingBox.model_validate(
287+
element["bbox"]
288+
).scaled(1 / self.scale)
289+
text_piece = page._backend.get_text_in_rect(the_bbox)
290+
element["bbox"]["token"] = text_piece
291+
element["bbox"] = _rotate_bbox(
292+
BoundingBox.model_validate(element["bbox"]),
293+
orientation=table_orientation,
294+
im_size=scaled_page_im.size,
295+
).model_dump()
296+
tc = TableCell.model_validate(element)
297+
if tc.bbox is not None:
298+
tc.bbox = tc.bbox.scaled(1 / self.scale)
299+
table_cells.append(tc)
300+
301+
assert "predict_details" in table_out
302+
303+
# Retrieving cols/rows, after post processing:
304+
num_rows = table_out["predict_details"].get("num_rows", 0)
305+
num_cols = table_out["predict_details"].get("num_cols", 0)
306+
otsl_seq = (
307+
table_out["predict_details"]
308+
.get("prediction", {})
309+
.get("rs_seq", [])
310+
)
311311

312-
tbl = Table(
313-
otsl_seq=otsl_seq,
314-
table_cells=table_cells,
315-
num_rows=num_rows,
316-
num_cols=num_cols,
317-
id=table_cluster.id,
318-
page_no=page.page_no,
319-
cluster=table_cluster,
320-
label=table_cluster.label,
321-
)
312+
tbl = Table(
313+
otsl_seq=otsl_seq,
314+
table_cells=table_cells,
315+
num_rows=num_rows,
316+
num_cols=num_cols,
317+
id=table_cluster.id,
318+
page_no=page.page_no,
319+
cluster=table_cluster,
320+
label=table_cluster.label,
321+
)
322322

323-
page.predictions.tablestructure.table_map[table_cluster.id] = tbl
323+
page.predictions.tablestructure.table_map[table_cluster.id] = tbl
324324

325325
# For debugging purposes:
326326
if settings.debug.visualize_tables:
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<doctag><section_header_level_1><loc_109><loc_79><loc_266><loc_87>1 Mixed table orientation</section_header_level_1>
22
<text><loc_109><loc_95><loc_390><loc_168>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante. Donec ullamcorper, felis non sodales commodo, lectus velit ultrices augue, a dignissim nibh lectus placerat pede. Vivamus nunc nunc, molestie ut, ultricies vel, semper in, velit. Ut porttitor. Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis fringilla tristique neque. Sed interdum libero ut metus. Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit amet ante lobortis sollicitudin. Praesent blandit blandit mauris. Praesent lectus tellus, aliquet aliquam, luctus a, egestas a, turpis. Mauris lacinia lorem sit amet ipsum. Nunc quis urna dictum turpis accumsan semper.</text>
3-
<picture><loc_120><loc_194><loc_191><loc_379></picture>
3+
<picture><loc_121><loc_194><loc_183><loc_379><caption><loc_181><loc_236><loc_191><loc_338>Table 1: This is a table rotated 90 °</caption></picture>
4+
<otsl><loc_121><loc_194><loc_183><loc_379><ched>Column 1<ched>Column 2<ched>Column 3<nl><fcel>There should be something written here<fcel>But also here<fcel>And here<nl></otsl>
45
<text><loc_121><loc_408><loc_177><loc_414>Interesting no ?</text>
56
</doctag>

0 commit comments

Comments
 (0)