import requests
from transformers import (
DFineForObjectDetection,
RTDetrImageProcessor,
)
import torch
from PIL import Image
classes_map = {
0: "Caption",
1: "Footnote",
2: "Formula",
3: "List-item",
4: "Page-footer",
5: "Page-header",
6: "Picture",
7: "Section-header",
8: "Table",
9: "Text",
10: "Title",
11: "Document Index",
12: "Code",
13: "Checkbox-Selected",
14: "Checkbox-Unselected",
15: "Form",
16: "Key-Value Region",
}
image_url = "https://huggingface.co/spaces/ds4sd/SmolDocling-256M-Demo/resolve/main/example_images/annual_rep_14.png"
model_name = "ds4sd/docling-layout-egret-large"
threshold = 0.6# Download the image
image = Image.open(requests.get(image_url, stream=True).raw)
image = image.convert("RGB")
# Initialize the model
image_processor = RTDetrImageProcessor.from_pretrained(model_name)
model = DFineForObjectDetection.from_pretrained(model_name)
# Run the prediction pipeline
inputs = image_processor(images=[image], return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
results = image_processor.post_process_object_detection(
outputs,
target_sizes=torch.tensor([image.size[::-1]]),
threshold=threshold,
)
# Get the resultsfor result in results:
for score, label_id, box inzip(
result["scores"], result["labels"], result["boxes"]
):
score = round(score.item(), 2)
label = classes_map[label_id.item()]
box = [round(i, 2) for i in box.tolist()]
print(f"{label}:{score}{box}")
References
@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}
}
@misc{peng2024dfine,
title={D-FINE: Redefine Regression Task in DETRs as Fine-grained Distribution Refinement},
author={Yansong Peng and Hebei Li and Peixi Wu and Yueyi Zhang and Xiaoyan Sun and Feng Wu},
year={2024},
eprint={2410.13842},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
Runs of docling-project docling-layout-egret-large on huggingface.co
5.5K
Total runs
61
24-hour runs
-16
3-day runs
-30
7-day runs
2.0K
30-day runs
More Information About docling-layout-egret-large huggingface.co Model
More docling-layout-egret-large license Visit here:
docling-layout-egret-large huggingface.co is an AI model on huggingface.co that provides docling-layout-egret-large's model effect (), which can be used instantly with this docling-project docling-layout-egret-large model. huggingface.co supports a free trial of the docling-layout-egret-large model, and also provides paid use of the docling-layout-egret-large. Support call docling-layout-egret-large model through api, including Node.js, Python, http.
docling-layout-egret-large huggingface.co is an online trial and call api platform, which integrates docling-layout-egret-large's modeling effects, including api services, and provides a free online trial of docling-layout-egret-large, you can try docling-layout-egret-large online for free by clicking the link below.
docling-project docling-layout-egret-large online free url in huggingface.co:
docling-layout-egret-large is an open source model from GitHub that offers a free installation service, and any user can find docling-layout-egret-large on GitHub to install. At the same time, huggingface.co provides the effect of docling-layout-egret-large install, users can directly use docling-layout-egret-large installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
docling-layout-egret-large install url in huggingface.co: