Spaces:
Running
Running
feat: π enhance predict_image function with additional parameters and update example usage
Browse files- app.py +12 -8
- requirements.txt +0 -4
app.py
CHANGED
|
@@ -2,22 +2,21 @@
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import PIL.Image as Image
|
| 5 |
-
|
| 6 |
from ultralytics import ASSETS, YOLO
|
| 7 |
|
| 8 |
model = None
|
| 9 |
|
| 10 |
|
| 11 |
-
def predict_image(img, conf_threshold, iou_threshold, model_name):
|
| 12 |
"""Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
|
| 13 |
model = YOLO(model_name)
|
| 14 |
results = model.predict(
|
| 15 |
source=img,
|
| 16 |
conf=conf_threshold,
|
| 17 |
iou=iou_threshold,
|
| 18 |
-
show_labels=
|
| 19 |
-
show_conf=
|
| 20 |
-
imgsz=
|
| 21 |
)
|
| 22 |
|
| 23 |
for r in results:
|
|
@@ -33,14 +32,19 @@ iface = gr.Interface(
|
|
| 33 |
gr.Image(type="pil", label="Upload Image"),
|
| 34 |
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
| 35 |
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
| 36 |
-
gr.Radio(choices=["yolov8n", "yolov8s", "yolov8m"], label="Model Name", value="yolov8n"),
|
|
|
|
|
|
|
|
|
|
| 37 |
],
|
| 38 |
outputs=gr.Image(type="pil", label="Result"),
|
| 39 |
title="Ultralytics Gradio Application π",
|
| 40 |
description="Upload images for inference. The Ultralytics YOLOv8n model is used by default.",
|
| 41 |
examples=[
|
| 42 |
-
[ASSETS / "bus.jpg", 0.25, 0.45, "yolov8n
|
| 43 |
-
[ASSETS / "zidane.jpg", 0.25, 0.45, "yolov8n
|
|
|
|
|
|
|
| 44 |
],
|
| 45 |
)
|
| 46 |
iface.launch(share=True)
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
import PIL.Image as Image
|
|
|
|
| 5 |
from ultralytics import ASSETS, YOLO
|
| 6 |
|
| 7 |
model = None
|
| 8 |
|
| 9 |
|
| 10 |
+
def predict_image(img, conf_threshold, iou_threshold, model_name, show_labels, show_conf, imgsz):
|
| 11 |
"""Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
|
| 12 |
model = YOLO(model_name)
|
| 13 |
results = model.predict(
|
| 14 |
source=img,
|
| 15 |
conf=conf_threshold,
|
| 16 |
iou=iou_threshold,
|
| 17 |
+
show_labels=show_labels,
|
| 18 |
+
show_conf=show_conf,
|
| 19 |
+
imgsz=imgsz,
|
| 20 |
)
|
| 21 |
|
| 22 |
for r in results:
|
|
|
|
| 32 |
gr.Image(type="pil", label="Upload Image"),
|
| 33 |
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
| 34 |
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
|
| 35 |
+
gr.Radio(choices=["yolov8n", "yolov8s", "yolov8m", "yolov8n-seg", "yolov8s-seg", "yolov8m-seg", "yolov8n-pose", "yolov8s-pose", "yolov8m-pose"], label="Model Name", value="yolov8n"),
|
| 36 |
+
gr.Checkbox(value=True, label="Show Labels"),
|
| 37 |
+
gr.Checkbox(value=True, label="Show Confidence"),
|
| 38 |
+
gr.Radio(choices=[320, 640, 1000], label="Image Size", value=640),
|
| 39 |
],
|
| 40 |
outputs=gr.Image(type="pil", label="Result"),
|
| 41 |
title="Ultralytics Gradio Application π",
|
| 42 |
description="Upload images for inference. The Ultralytics YOLOv8n model is used by default.",
|
| 43 |
examples=[
|
| 44 |
+
[ASSETS / "bus.jpg", 0.25, 0.45, "yolov8n", True, True, 640],
|
| 45 |
+
[ASSETS / "zidane.jpg", 0.25, 0.45, "yolov8n", True, True, 640],
|
| 46 |
+
[ASSETS / "bus.jpg", 0.25, 0.45, "yolov8n-seg", True, True, 640],
|
| 47 |
+
[ASSETS / "zidane.jpg", 0.25, 0.45, "yolov8n-seg", True, True, 640],
|
| 48 |
],
|
| 49 |
)
|
| 50 |
iface.launch(share=True)
|
requirements.txt
CHANGED
|
@@ -1,6 +1,2 @@
|
|
| 1 |
gradio
|
| 2 |
-
torch>=1.8.0
|
| 3 |
-
torch>=1.8.0,!=2.4.0; sys_platform == 'win32' # Windows CPU errors w/ 2.4.0 https://github.com/ultralytics/ultralytics/issues/15049
|
| 4 |
-
torchvision>=0.9.0
|
| 5 |
ultralytics
|
| 6 |
-
Pillow
|
|
|
|
| 1 |
gradio
|
|
|
|
|
|
|
|
|
|
| 2 |
ultralytics
|
|
|