TahaDouaji/detr-doc-table-detection is a forked repo from huggingface. License: None
Go to file
Taha Douaji 7207383528 Update README.md 2023-01-03 06:44:07 +00:00
.gitattributes initial commit 2022-03-11 15:55:14 +00:00
README.md Update README.md 2023-01-03 06:44:07 +00:00
config.json Update config.json 2022-03-11 22:43:07 +00:00
preprocessor_config.json Update preprocessor_config.json 2022-03-12 11:59:43 +00:00
pytorch_model.bin add model 2022-03-11 16:03:02 +00:00

README.md

from transformers import DetrImageProcessor, DetrForObjectDetection
import torch
from PIL import Image
import requests

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)

processor = DetrImageProcessor.from_pretrained("TahaDouaji/detr-doc-table-detection")
model = DetrForObjectDetection.from_pretrained("TahaDouaji/detr-doc-table-detection")

inputs = processor(images=image, return_tensors="pt")
outputs = model(**inputs)

# convert outputs (bounding boxes and class logits) to COCO API
# let's only keep detections with score > 0.9
target_sizes = torch.tensor([image.size[::-1]])
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]

for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
    box = [round(i, 2) for i in box.tolist()]
    print(
            f"Detected {model.config.id2label[label.item()]} with confidence "
            f"{round(score.item(), 3)} at location {box}"
    )