Views
No views yet
egret-large is a Document Layout Analysis Model used in the Docling project.pip install transformers Pillow torch requests1import requests
2from transformers import (
3 DFineForObjectDetection,
4 RTDetrImageProcessor,
5)
6import torch
7from PIL import Image
8
9
10classes_map = {
11 0: "Caption",
12 1: "Footnote",
13 2: "Formula",
14 3: "List-item",
15 4: "Page-footer",
16 5: "Page-header",
17 6: "Picture",
18 7: "Section-header",
19 8: "Table",
20 9: "Text",
21 10: "Title",
22 11: "Document Index",
23 12: "Code",
24 13: "Checkbox-Selected",
25 14: "Checkbox-Unselected",
26 15: "Form",
27 16: "Key-Value Region",
28}
29image_url = "https://huggingface.co/spaces/ds4sd/SmolDocling-256M-Demo/resolve/main/example_images/annual_rep_14.png"
30model_name = "ds4sd/docling-layout-egret-large"
31threshold = 0.6
32
33# Download the image
34image = Image.open(requests.get(image_url, stream=True).raw)
35image = image.convert("RGB")
36
37
38# Initialize the model
39image_processor = RTDetrImageProcessor.from_pretrained(model_name)
40model = DFineForObjectDetection.from_pretrained(model_name)
41
42# Run the prediction pipeline
43inputs = image_processor(images=[image], return_tensors="pt")
44with torch.no_grad():
45 outputs = model(**inputs)
46results = image_processor.post_process_object_detection(
47 outputs,
48 target_sizes=torch.tensor([image.size[::-1]]),
49 threshold=threshold,
50)
51
52# Get the results
53for result in results:
54 for score, label_id, box in zip(
55 result["scores"], result["labels"], result["boxes"]
56 ):
57 score = round(score.item(), 2)
58 label = classes_map[label_id.item()]
59 box = [round(i, 2) for i in box.tolist()]
60 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}
}