@@ -177,12 +177,13 @@ def get_class_map(data_type: str):
177177
178178
179179structure_class_thresholds = {
180- "table" : 0.5 ,
181- "table column" : 0.5 ,
182- "table row" : 0.5 ,
183- "table column header" : 0.5 ,
184- "table projected row header" : 0.5 ,
185- "table spanning cell" : 0.5 ,
180+ "table" : inference_config .TT_TABLE_CONF ,
181+ "table column" : inference_config .TABLE_COLUMN_CONF ,
182+ "table row" : inference_config .TABLE_ROW_CONF ,
183+ "table column header" : inference_config .TABLE_COLUMN_HEADER_CONF ,
184+ "table projected row header" : inference_config .TABLE_PROJECTED_ROW_HEADER_CONF ,
185+ "table spanning cell" : inference_config .TABLE_SPANNING_CELL_CONF ,
186+ # FIXME (yao) this parameter doesn't seem to be used at all in inference? Can we remove it
186187 "no object" : 10 ,
187188}
188189
@@ -282,8 +283,16 @@ def objects_to_structures(objects, tokens, class_thresholds):
282283 table_structures = []
283284
284285 for table in tables :
285- table_objects = [obj for obj in objects if iob (obj ["bbox" ], table ["bbox" ]) >= 0.5 ]
286- table_tokens = [token for token in tokens if iob (token ["bbox" ], table ["bbox" ]) >= 0.5 ]
286+ table_objects = [
287+ obj
288+ for obj in objects
289+ if iob (obj ["bbox" ], table ["bbox" ]) >= inference_config .TABLE_IOB_THRESHOLD
290+ ]
291+ table_tokens = [
292+ token
293+ for token in tokens
294+ if iob (token ["bbox" ], table ["bbox" ]) >= inference_config .TABLE_IOB_THRESHOLD
295+ ]
287296
288297 structure = {}
289298
@@ -302,7 +311,7 @@ def objects_to_structures(objects, tokens, class_thresholds):
302311 for obj in rows :
303312 obj ["column header" ] = False
304313 for header_obj in column_headers :
305- if iob (obj ["bbox" ], header_obj ["bbox" ]) >= 0.5 :
314+ if iob (obj ["bbox" ], header_obj ["bbox" ]) >= inference_config . TABLE_IOB_THRESHOLD :
306315 obj ["column header" ] = True
307316
308317 # Refine table structures
@@ -478,7 +487,7 @@ def structure_to_cells(table_structure, tokens):
478487 spanning_cell_rect = Rect (list (spanning_cell ["bbox" ]))
479488 if (
480489 spanning_cell_rect .intersect (cell_rect ).get_area () / cell_rect .get_area ()
481- ) > 0.5 :
490+ ) > inference_config . TABLE_IOB_THRESHOLD :
482491 cell ["subcell" ] = True
483492 break
484493
@@ -499,7 +508,9 @@ def structure_to_cells(table_structure, tokens):
499508 for subcell in subcells :
500509 subcell_rect = Rect (list (subcell ["bbox" ]))
501510 subcell_rect_area = subcell_rect .get_area ()
502- if (subcell_rect .intersect (spanning_cell_rect ).get_area () / subcell_rect_area ) > 0.5 :
511+ if (
512+ subcell_rect .intersect (spanning_cell_rect ).get_area () / subcell_rect_area
513+ ) > inference_config .TABLE_IOB_THRESHOLD :
503514 if cell_rect is None :
504515 cell_rect = Rect (list (subcell ["bbox" ]))
505516 else :
0 commit comments