|
Download README.md from cimo001/docling: direct link, hf CLI and curl.
- Browser
- Download file 4.73 kB
-
https://huggingface.co/cimo001/docling/resolve/main/README.md
- Command line
-
hf download hf://cimo001/docling/README.md
-
curl -L -o README.md https://huggingface.co/cimo001/docling/resolve/main/README.md
4.73 kB
| license: apache-2.0 | |
| base_model: docling-project | |
| pipeline_tag: object-detection | |
| library_name: onnx | |
| language: | |
| - multilingual | |
| tags: | |
| - layout | |
| - docling | |
| - onnx | |
| # ONNX - Docling | |
| | Model | FP32 | Task | | |
| | --- | --- | --- | | |
| | Docling-Layout-Heron | docling-layout-heron.onnx | layout detection | | |
| | TableFormer | tableFormer_encoder.onnx, tableFormer_decoder.onnx, tableFormer_box.onnx | table structure recognition | | |
| ## 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, postprocess | |
| - `onnx/` = the model file | |
| Run the commands from the repository root. | |
| Test images used by the examples: | |
| - [jp_1.jpg](https://github.com/cimo/One_workspace/blob/main/file/test/invoice/jp_1.jpg) = full page | |
| - [Table_1.jpg](https://github.com/cimo/One_workspace/blob/main/file/test/table/1.jpg) = single table | |
| ## Docling-Layout-Heron | |
| - [Docling-Layout-Heron/src/example.py](Docling-Layout-Heron/src/example.py) | |
| ``` | |
| python3 Docling-Layout-Heron/src/example.py jp_1.jpg | |
| ``` | |
| ``` | |
| 0.956688 | table | [1066, 852, 1692, 991] | |
| 0.951113 | table | [57, 397, 1691, 782] | |
| 0.932638 | table | [1063, 176, 1692, 260] | |
| 0.929594 | page_footer | [1069, 1159, 1199, 1176] | |
| 0.878344 | section_header | [797, 141, 953, 166] | |
| ``` | |
| Note: | |
| - Input = RGB image resized to 640x640 (bilinear), float32 0..1, CHW with batch dimension. | |
| - Feed = `pixel_values`, the only input, fixed shape `[1, 3, 640, 640]`. | |
| - Output = `logits` `[1, 300, 17]` (raw, apply the sigmoid) and `pred_boxes` `[1, 300, 4]` as<br> | |
| `[centerX, centerY, width, height]` in the 0..1 range: multiply by the original image size. | |
| - 17 label classes (caption, footnote, formula, list_item, page_footer, page_header, picture, section_header,<br> | |
| table, text, title, ...): full list in [Docling-Layout-Heron/src/example.py](Docling-Layout-Heron/src/example.py). | |
| - 300 queries per image, no NMS in the model: filter by score (0.5 in the example) and handle the overlap<br> | |
| on your side. The same box can come out with two labels. | |
| ## TableFormer | |
| - [TableFormer/src/example.py](TableFormer/src/example.py) | |
| ``` | |
| python3 TableFormer/src/example.py Table_1.jpg | |
| ``` | |
| ``` | |
| fcel fcel fcel fcel fcel fcel fcel fcel fcel fcel nl | |
| rhed fcel fcel fcel fcel fcel fcel fcel fcel fcel nl | |
| rhed fcel fcel fcel fcel fcel fcel fcel fcel fcel nl | |
| rhed fcel fcel fcel fcel fcel fcel fcel fcel fcel nl | |
| rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl | |
| rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl | |
| rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl | |
| rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl | |
| rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl | |
| rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl | |
| rhed ecel ecel ecel ecel ecel fcel fcel fcel fcel nl | |
| rhed lcel lcel lcel fcel fcel fcel fcel fcel fcel nl | |
| [24, 31, 127, 79] | |
| [180, 33, 279, 79] | |
| [333, 27, 436, 83] | |
| [581, 35, 866, 84] | |
| [1003, 6, 1094, 78] | |
| ``` | |
| Note: | |
| - Input = a single table crop, not a full page: use the `table` boxes from Docling-Layout-Heron. | |
| - Input = RGB image resized to height 1024, normalized with the table mean / std (values in the example),<br> | |
| resized to 448x448, transposed to `[channel, width, height]` (width before height) with batch dimension. | |
| - Three graphs, exported with fixed shapes:<br> | |
| `tableFormer_encoder.onnx` = feed `image` `[1, 3, 448, 448]`, output `memory` `[784, 1, 512]` and `box` `[1, 784, 512]`;<br> | |
| `tableFormer_decoder.onnx` = one tag per call, feed `tag` `[1]`, `position` `[1]`, `memory` and `buffer` `[6, 1024, 1, 512]`,<br> | |
| output `logit` `[1, 13]`, `hidden` `[1, 512]` and `state` `[6, 1, 1, 512]`;<br> | |
| `tableFormer_box.onnx` = feed `box` and `hidden` `[32, 512]` (zero padded), output `class` `[32, 3]` and `coordinate` `[32, 4]`. | |
| - Decode = greedy: start from `<start>`, write `state` in `buffer[:, position]` after every call, stop at `<end>`<br> | |
| or at 1024 tags. | |
| - Tag = OTSL: `fcel` cell with content, `ecel` empty cell, `lcel` merged with the cell on the left, `ucel` merged with<br> | |
| the cell above, `xcel` merged with both, `ched` column header, `rhed` row header, `srow` section row, `nl` end of the row. | |
| - The first output of the example is the grid, one line per table row. The second is one box per cell, in the same<br> | |
| order as the cells of the grid (`lcel`, `ucel`, `xcel` and `nl` have no box), `[x1, y1, x2, y2]` in the table crop space. | |
| - A cell merged over several columns gets a single box that goes from its first to its last column. | |
| - The model gives the structure only: read the text with an OCR model and assign it to the cells by box overlap. | |