Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
from transformers import DetrImageProcessor, DetrForObjectDetection
|
| 2 |
import torch
|
| 3 |
-
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
-
import requests
|
| 6 |
-
import random
|
| 7 |
|
| 8 |
def detect_objects(image):
|
| 9 |
# Load the pre-trained DETR model
|
|
@@ -18,13 +18,6 @@ def detect_objects(image):
|
|
| 18 |
target_sizes = torch.tensor([image.size[::-1]])
|
| 19 |
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
|
| 20 |
|
| 21 |
-
# Draw bounding boxes and labels on the image
|
| 22 |
-
#draw = ImageDraw.Draw(image)
|
| 23 |
-
#for i, (score, label, box) in enumerate(zip(results["scores"], results["labels"], results["boxes"])):
|
| 24 |
-
# box = [round(i, 2) for i in box.tolist()]
|
| 25 |
-
# color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
|
| 26 |
-
# draw.rectangle(box, outline=color, width=3)
|
| 27 |
-
# draw.text((box[0], box[1]), model.config.id2label[label.item()], fill=color)
|
| 28 |
res = []
|
| 29 |
for label in results["labels"]:
|
| 30 |
res.append(model.config.id2label[label.item()])
|
|
|
|
| 1 |
from transformers import DetrImageProcessor, DetrForObjectDetection
|
| 2 |
import torch
|
| 3 |
+
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
+
# import requests
|
| 6 |
+
# import random
|
| 7 |
|
| 8 |
def detect_objects(image):
|
| 9 |
# Load the pre-trained DETR model
|
|
|
|
| 18 |
target_sizes = torch.tensor([image.size[::-1]])
|
| 19 |
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
res = []
|
| 22 |
for label in results["labels"]:
|
| 23 |
res.append(model.config.id2label[label.item()])
|