subh71 commited on
Commit
82fec7c
·
verified ·
1 Parent(s): bfba0e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -8,8 +8,7 @@ import requests
8
  from transformers import AutoImageProcessor, AutoModelForObjectDetection
9
  from transformers import AutoImageProcessor, DetrForObjectDetection
10
 
11
- def model():
12
-
13
 
14
  url = "http://images.cocodataset.org/val2017/000000039769.jpg"
15
  image = Image.open(requests.get(url, stream=True).raw)
@@ -22,17 +21,15 @@ def model():
22
 
23
  # convert outputs (bounding boxes and class logits) to Pascal VOC format (xmin, ymin, xmax, ymax)
24
  target_sizes = torch.tensor([image.size[::-1]])
25
- results = image_processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[
26
- 0
27
- ]
28
 
29
  for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
30
  box = [round(i, 2) for i in box.tolist()]
31
  st.write("Prediction:", result[0]['label'], "| Score:", result[0]['score'])
32
- print(
33
- f"Detected {model.config.id2label[label.item()]} with confidence "
34
- f"{round(score.item(), 3)} at location {box}"
35
- )
36
 
37
 
38
 
 
8
  from transformers import AutoImageProcessor, AutoModelForObjectDetection
9
  from transformers import AutoImageProcessor, DetrForObjectDetection
10
 
11
+ def model():
 
12
 
13
  url = "http://images.cocodataset.org/val2017/000000039769.jpg"
14
  image = Image.open(requests.get(url, stream=True).raw)
 
21
 
22
  # convert outputs (bounding boxes and class logits) to Pascal VOC format (xmin, ymin, xmax, ymax)
23
  target_sizes = torch.tensor([image.size[::-1]])
24
+ results = image_processor.post_process_object_detection(outputs, threshold=0.9, target_sizes=target_sizes)[0]
 
 
25
 
26
  for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
27
  box = [round(i, 2) for i in box.tolist()]
28
  st.write("Prediction:", result[0]['label'], "| Score:", result[0]['score'])
29
+ #print(
30
+ # f"Detected {model.config.id2label[label.item()]} with confidence "
31
+ # f"{round(score.item(), 3)} at location {box}"
32
+ # )
33
 
34
 
35