Update README.md
Browse files
README.md
CHANGED
@@ -13,18 +13,29 @@ The model was trained on ICDAR2019 Table Dataset
|
|
13 |
### How to use
|
14 |
|
15 |
```python
|
16 |
-
from transformers import
|
|
|
17 |
from PIL import Image
|
|
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
-
|
22 |
-
model = DetrForObjectDetection.from_pretrained(
|
23 |
|
24 |
-
inputs =
|
25 |
outputs = model(**inputs)
|
26 |
|
27 |
# convert outputs (bounding boxes and class logits) to COCO API
|
|
|
28 |
target_sizes = torch.tensor([image.size[::-1]])
|
29 |
-
results =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
```
|
|
|
13 |
### How to use
|
14 |
|
15 |
```python
|
16 |
+
from transformers import DetrImageProcessor, DetrForObjectDetection
|
17 |
+
import torch
|
18 |
from PIL import Image
|
19 |
+
import requests
|
20 |
|
21 |
+
url = "http://images.cocodataset.org/val2017/000000039769.jpg"
|
22 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
23 |
|
24 |
+
processor = DetrImageProcessor.from_pretrained("TahaDouaji/detr-doc-table-detection")
|
25 |
+
model = DetrForObjectDetection.from_pretrained("TahaDouaji/detr-doc-table-detection")
|
26 |
|
27 |
+
inputs = processor(images=image, return_tensors="pt")
|
28 |
outputs = model(**inputs)
|
29 |
|
30 |
# convert outputs (bounding boxes and class logits) to COCO API
|
31 |
+
# let's only keep detections with score > 0.9
|
32 |
target_sizes = torch.tensor([image.size[::-1]])
|
33 |
+
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
|
34 |
+
|
35 |
+
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
36 |
+
box = [round(i, 2) for i in box.tolist()]
|
37 |
+
print(
|
38 |
+
f"Detected {model.config.id2label[label.item()]} with confidence "
|
39 |
+
f"{round(score.item(), 3)} at location {box}"
|
40 |
+
)
|
41 |
```
|