Views
No views yet

heron is the default layout analysis model of the Docling project, designed for robust and high-quality document layout understanding.pip install transformers Pillow torch requests1import requests
2from transformers import RTDetrV2ForObjectDetection, RTDetrImageProcessor
3import torch
4from PIL import Image
5
6
7classes_map = {
8 0: "Caption",
9 1: "Footnote",
10 2: "Formula",
11 3: "List-item",
12 4: "Page-footer",
13 5: "Page-header",
14 6: "Picture",
15 7: "Section-header",
16 8: "Table",
17 9: "Text",
18 10: "Title",
19 11: "Document Index",
20 12: "Code",
21 13: "Checkbox-Selected",
22 14: "Checkbox-Unselected",
23 15: "Form",
24 16: "Key-Value Region",
25}
26image_url = "https://huggingface.co/spaces/ds4sd/SmolDocling-256M-Demo/resolve/main/example_images/annual_rep_14.png"
27model_name = "docling-project/docling-layout-heron"
28threshold = 0.6
29
30
31# Download the image
32image = Image.open(requests.get(image_url, stream=True).raw)
33image = image.convert("RGB")
34
35# Initialize the model
36image_processor = RTDetrImageProcessor.from_pretrained(model_name)
37model = RTDetrV2ForObjectDetection.from_pretrained(model_name)
38
39# Run the prediction pipeline
40inputs = image_processor(images=[image], return_tensors="pt")
41with torch.no_grad():
42 outputs = model(**inputs)
43results = image_processor.post_process_object_detection(
44 outputs,
45 target_sizes=torch.tensor([image.size[::-1]]),
46 threshold=threshold,
47)
48
49# Get the results
50for result in results:
51 for score, label_id, box in zip(
52 result["scores"], result["labels"], result["boxes"]
53 ):
54 score = round(score.item(), 2)
55 label = classes_map[label_id.item()]
56 box = [round(i, 2) for i in box.tolist()]
57 print(f"{label}:{score} {box}")@misc{livathinos2025advancedlayoutanalysismodels,
title={advanced layout analysis models for docling},
author={nikolaos livathinos and christoph auer and ahmed nassar and rafael teixeira de lima and maksym lysak and brown ebouky and cesar berrospi and michele dolfi and panagiotis vagenas and matteo omenetti and kasper dinkla and yusik kim and valery weber and lucas morin and ingmar meijer and viktor kuropiatnyk and tim strohmeyer and a. said gurbuz and peter w. j. staar},
year={2025},
eprint={2509.11720},
archiveprefix={arxiv},
primaryclass={cs.cv},
url={https://arxiv.org/abs/2509.11720},
}
@techreport{Docling,
author = {Deep Search Team},
month = {8},
title = {Docling Technical Report},
url = {https://arxiv.org/abs/2408.09869v4},
eprint = {2408.09869},
doi = {10.48550/arXiv.2408.09869},
version = {1.0.0},
year = {2024}
}