Spaces:
Runtime error
Runtime error
pytorch/YOLOv5
#1
by
Liuli
- opened
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from PIL import Image
|
4 |
-
|
5 |
# Images
|
6 |
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
|
7 |
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/bus.jpg', 'bus.jpg')
|
@@ -9,19 +9,18 @@ torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master
|
|
9 |
# Model
|
10 |
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # force_reload=True to update
|
11 |
|
|
|
12 |
def yolo(im, size=640):
|
13 |
g = (size / max(im.size)) # gain
|
14 |
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
15 |
|
16 |
results = model(im) # inference
|
17 |
results.render() # updates results.imgs with boxes and labels
|
18 |
-
results.
|
19 |
-
os.system("ls")
|
20 |
-
return "out.png"
|
21 |
|
22 |
|
23 |
inputs = gr.inputs.Image(type='pil', label="Original Image")
|
24 |
-
outputs = gr.outputs.Image(type="
|
25 |
|
26 |
title = "YOLOv5"
|
27 |
description = "YOLOv5 Gradio demo for object detection. Upload an image or click an example image to use."
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from PIL import Image
|
4 |
+
|
5 |
# Images
|
6 |
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
|
7 |
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/bus.jpg', 'bus.jpg')
|
|
|
9 |
# Model
|
10 |
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # force_reload=True to update
|
11 |
|
12 |
+
|
13 |
def yolo(im, size=640):
|
14 |
g = (size / max(im.size)) # gain
|
15 |
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
16 |
|
17 |
results = model(im) # inference
|
18 |
results.render() # updates results.imgs with boxes and labels
|
19 |
+
return Image.fromarray(results.imgs[0])
|
|
|
|
|
20 |
|
21 |
|
22 |
inputs = gr.inputs.Image(type='pil', label="Original Image")
|
23 |
+
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
24 |
|
25 |
title = "YOLOv5"
|
26 |
description = "YOLOv5 Gradio demo for object detection. Upload an image or click an example image to use."
|