Instructions to use zeromodels/table-transformer-structure-recognition with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use zeromodels/table-transformer-structure-recognition with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/table-transformer-structure-recognition") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- README.md +92 -0
- model.weights.h5 +3 -0
- zm_config.json +21 -0
- zm_preprocessor.json +27 -0
README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: object-detection
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
base_model: microsoft/table-transformer-structure-recognition
|
| 5 |
+
library_name: zeromodels
|
| 6 |
+
tags:
|
| 7 |
+
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
+
- table-transformer
|
| 10 |
+
- detr
|
| 11 |
+
- object-detection
|
| 12 |
+
- arxiv:2110.00061
|
| 13 |
+
- pytorch
|
| 14 |
+
- jax
|
| 15 |
+
- tf
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/table-transformer-6a928f000a88c73a41f9411e) for all versions of Table Transformer.***
|
| 19 |
+
|
| 20 |
+
# Run Table Transformer with Keras 3: JAX, PyTorch, or TensorFlow
|
| 21 |
+
|
| 22 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/table_transformer/) [](https://huggingface.co/collections/zeromodels/table-transformer-6a928f000a88c73a41f9411e)
|
| 23 |
+
|
| 24 |
+
# zeromodels/table-transformer-structure-recognition
|
| 25 |
+
|
| 26 |
+
Paper: [PubTables-1M: Towards comprehensive table extraction from unstructured documents (arXiv:2110.00061)](https://arxiv.org/abs/2110.00061) · [HF Papers](https://huggingface.co/papers/2110.00061)
|
| 27 |
+
|
| 28 |
+
Table Transformer (TATR) applies the DETR detection recipe to tables. A ResNet-18 backbone produces a feature map, a transformer encoder-decoder attends over it with a fixed set of learned object queries, and each query emits one class and one box, with no anchors and no NMS. This structure-recognition checkpoint decomposes a cropped table into its rows, columns, and header / spanning cells.
|
| 29 |
+
|
| 30 |
+
For more details on the model, please go to Microsoft's original [model card](https://huggingface.co/microsoft/table-transformer-structure-recognition).
|
| 31 |
+
|
| 32 |
+
Pure-**Keras 3** conversion of [`microsoft/table-transformer-structure-recognition`](https://huggingface.co/microsoft/table-transformer-structure-recognition) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 33 |
+
|
| 34 |
+
This is a **table-structure recognition** checkpoint (`TableTransformerDetect`): each query predicts a table element (classes: table, column, row, column header, projected row header, spanning cell).
|
| 35 |
+
|
| 36 |
+
## ✨ Quick start
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
import os
|
| 40 |
+
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 41 |
+
|
| 42 |
+
from PIL import Image
|
| 43 |
+
from zeromodels.models.table_transformer import (
|
| 44 |
+
TableTransformerDetect,
|
| 45 |
+
TableTransformerImageProcessor,
|
| 46 |
+
)
|
| 47 |
+
from zeromodels.models.table_transformer.table_transformer_image_processor import (
|
| 48 |
+
TABLE_STRUCTURE_LABELS,
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
model = TableTransformerDetect.from_weights("zeromodels/table-transformer-structure-recognition")
|
| 52 |
+
processor = TableTransformerImageProcessor.from_weights("zeromodels/table-transformer-structure-recognition")
|
| 53 |
+
|
| 54 |
+
image = Image.open("your_image.jpg").convert("RGB")
|
| 55 |
+
inputs = processor(image)
|
| 56 |
+
output = model(inputs["pixel_values"], training=False)
|
| 57 |
+
results = processor.post_process_object_detection(
|
| 58 |
+
output,
|
| 59 |
+
threshold=0.6,
|
| 60 |
+
target_sizes=[(image.height, image.width)],
|
| 61 |
+
label_names=TABLE_STRUCTURE_LABELS,
|
| 62 |
+
)[0]
|
| 63 |
+
for score, name, box in zip(
|
| 64 |
+
results["scores"], results["label_names"], results["boxes"]
|
| 65 |
+
):
|
| 66 |
+
print(f"{name}: {float(score):.3f} {box}")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
Load any Table Transformer variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 70 |
+
|
| 71 |
+
| Variant | Hub | Task |
|
| 72 |
+
|---|---|---|
|
| 73 |
+
| `table-transformer-detection` | [`zeromodels/table-transformer-detection`](https://huggingface.co/zeromodels/table-transformer-detection) | table detection |
|
| 74 |
+
| `table-transformer-structure-recognition` | [`zeromodels/table-transformer-structure-recognition`](https://huggingface.co/zeromodels/table-transformer-structure-recognition) | table-structure recognition |
|
| 75 |
+
| `table-transformer-structure-recognition-v1.1-all` | [`zeromodels/table-transformer-structure-recognition-v1.1-all`](https://huggingface.co/zeromodels/table-transformer-structure-recognition-v1.1-all) | table-structure recognition |
|
| 76 |
+
| `table-transformer-structure-recognition-v1.1-fin` | [`zeromodels/table-transformer-structure-recognition-v1.1-fin`](https://huggingface.co/zeromodels/table-transformer-structure-recognition-v1.1-fin) | table-structure recognition |
|
| 77 |
+
| `table-transformer-structure-recognition-v1.1-pub` | [`zeromodels/table-transformer-structure-recognition-v1.1-pub`](https://huggingface.co/zeromodels/table-transformer-structure-recognition-v1.1-pub) | table-structure recognition |
|
| 78 |
+
|
| 79 |
+
## Tips
|
| 80 |
+
|
| 81 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 82 |
+
- Detection finds tables in a page image; structure recognition decomposes a cropped table into rows, columns, and header / spanning cells.
|
| 83 |
+
- Both tasks use `TableTransformerDetect` + `post_process_object_detection`; only the checkpoint and the class set differ.
|
| 84 |
+
- Pass `label_names=TABLE_DETECTION_LABELS` for the detection checkpoint and `label_names=TABLE_STRUCTURE_LABELS` for structure recognition (both live in `zeromodels.models.table_transformer.table_transformer_image_processor`).
|
| 85 |
+
- See [Table Transformer docs](https://imvision12.github.io/ZeroModels/table_transformer/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 86 |
+
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `TableTransformerDetect.from_weights("hf:microsoft/table-transformer-structure-recognition")`.
|
| 87 |
+
|
| 88 |
+
## Special Thanks
|
| 89 |
+
|
| 90 |
+
A huge thank you to the Microsoft Table Transformer authors for creating and releasing these models.
|
| 91 |
+
|
| 92 |
+
License: Apache 2.0.
|
model.weights.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:005a19304c3f5bc6a1a207adf45eee8d7ee6c5f94beb39a74b191a49a8510be1
|
| 3 |
+
size 116199352
|
zm_config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.7",
|
| 4 |
+
"model_module": "zeromodels.models.table_transformer",
|
| 5 |
+
"model_class": "TableTransformerDetect",
|
| 6 |
+
"variant": "table-transformer-structure-recognition",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"model_type": "table-transformer",
|
| 10 |
+
"vision_config": {
|
| 11 |
+
"hidden_dim": 256,
|
| 12 |
+
"num_heads": 8,
|
| 13 |
+
"num_encoder_layers": 6,
|
| 14 |
+
"num_decoder_layers": 6,
|
| 15 |
+
"dim_feedforward": 2048,
|
| 16 |
+
"dropout_rate": 0.1,
|
| 17 |
+
"num_queries": 125,
|
| 18 |
+
"num_classes": 7,
|
| 19 |
+
"image_size": 800
|
| 20 |
+
}
|
| 21 |
+
}
|
zm_preprocessor.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.7",
|
| 4 |
+
"preprocessor_module": "zeromodels.models.table_transformer",
|
| 5 |
+
"preprocessor_class": "TableTransformerImageProcessor",
|
| 6 |
+
"variant": "table-transformer-structure-recognition",
|
| 7 |
+
"size": {
|
| 8 |
+
"height": 800,
|
| 9 |
+
"width": 800
|
| 10 |
+
},
|
| 11 |
+
"resample": "bilinear",
|
| 12 |
+
"do_rescale": true,
|
| 13 |
+
"rescale_factor": 0.00392156862745098,
|
| 14 |
+
"do_normalize": true,
|
| 15 |
+
"image_mean": [
|
| 16 |
+
0.485,
|
| 17 |
+
0.456,
|
| 18 |
+
0.406
|
| 19 |
+
],
|
| 20 |
+
"image_std": [
|
| 21 |
+
0.229,
|
| 22 |
+
0.224,
|
| 23 |
+
0.225
|
| 24 |
+
],
|
| 25 |
+
"return_tensor": true,
|
| 26 |
+
"data_format": null
|
| 27 |
+
}
|