ONNX - Microsoft
| Model | FP32 | Task |
|---|---|---|
| table-transformer-structure-recognition-v1.1-all | model.onnx | table structure recognition (rows, columns, merged cells) |
Usage
# onnxruntime-gpu for run it on GPU
pip install onnxruntime opencv-python numpy
Every model folder has the same layout:
src/helper.py= onnx session builder (provider selection, threads, memory options)src/example.py= full pipeline: image preprocess, inference, postprocessonnx/= the model file
Run the commands from the repository root.
Test images used by the examples:
- Table_1.jpg = single table
table-transformer-structure-recognition-v1.1-all
python3 table-transformer-structure-recognition-v1.1-all/src/example.py Table_1.jpg
0.999784 | table column | [446, 3, 929, 393]
0.999746 | table column | [943, 4, 1118, 393]
0.999231 | table column | [1263, 3, 1390, 393]
0.999151 | table column | [153, 4, 313, 393]
0.999050 | table column | [1513, 4, 1639, 394]
Note:
- Input = a single table crop, not a full page.
- Input = RGB image resized so the longest side is 800 keeping the aspect ratio, scaled to 0..1 then
normalized with the ImageNet mean / std, CHW with batch dimension. - Feed =
pixel_values, the only input, with a dynamic shape. - Output =
logits[1, 125, 7](raw, apply the softmax) andpred_boxes[1, 125, 4]as
[centerX, centerY, width, height]in the 0..1 range: multiply by the table crop size. - 7 classes:
table,table column,table row,table column header,table projected row header,
table spanning cell,no object(dropped). - 125 queries per image, no NMS in the model: filter by score (0.5 in the example).
- Rows and columns come out as full width / full height bands: the cells are their intersections,
atable spanning cellbox marks the cells to merge.