Views
No views yet
1@article{DBLP:journals/corr/abs-2005-12872,
2 author = {Nicolas Carion and
3 Francisco Massa and
4 Gabriel Synnaeve and
5 Nicolas Usunier and
6 Alexander Kirillov and
7 Sergey Zagoruyko},
8 title = {End-to-End Object Detection with Transformers},
9 journal = {CoRR},
10 volume = {abs/2005.12872},
11 year = {2020},
12 url = {https://arxiv.org/abs/2005.12872},
13 archivePrefix = {arXiv},
14 eprint = {2005.12872},
15 timestamp = {Thu, 28 May 2020 17:38:09 +0200},
16 biburl = {https://dblp.org/rec/journals/corr/abs-2005-12872.bib},
17 bibsource = {dblp computer science bibliography, https://dblp.org}
18}1from transformers import DetrImageProcessor, DetrForObjectDetection
2import torch
3from PIL import Image
4import requests
5
6image = Image.open("IMAGE_PATH")
7
8processor = DetrImageProcessor.from_pretrained("TahaDouaji/detr-doc-table-detection")
9model = DetrForObjectDetection.from_pretrained("TahaDouaji/detr-doc-table-detection")
10
11inputs = processor(images=image, return_tensors="pt")
12outputs = model(**inputs)
13
14# convert outputs (bounding boxes and class logits) to COCO API
15# let's only keep detections with score > 0.9
16target_sizes = torch.tensor([image.size[::-1]])
17results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
18
19for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
20 box = [round(i, 2) for i in box.tolist()]
21 print(
22 f"Detected {model.config.id2label[label.item()]} with confidence "
23 f"{round(score.item(), 3)} at location {box}"
24 )