nielsr HF staff commited on
Commit
e05068a
1 Parent(s): d60c294

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +17 -6
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 DetrFeatureExtractor, DetrForObjectDetection
 
17
  from PIL import Image
 
18
 
19
- image = Image.open("Image path")
 
20
 
21
- feature_extractor = DetrFeatureExtractor.from_pretrained('TahaDouaji/detr-doc-table-detection')
22
- model = DetrForObjectDetection.from_pretrained('TahaDouaji/detr-doc-table-detection')
23
 
24
- inputs = feature_extractor(images=image, return_tensors="pt")
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 = feature_extractor.post_process(outputs, target_sizes=target_sizes)[0]
 
 
 
 
 
 
 
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
  ```