Spaces:
Runtime error
Runtime error
AbdurrahimBalta commited on
Commit ·
fe02ba6
1
Parent(s): b89cb10
deneme
Browse files- app.py +55 -0
- bus.jpg +0 -0
- requirements.txt +4 -0
- yolov8n.pt +3 -0
- yolov8s.pt +3 -0
- zidane.jpg +0 -0
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
from collections import Counter
|
| 4 |
+
import torch
|
| 5 |
+
import cv2
|
| 6 |
+
|
| 7 |
+
# torch.hub.download_url_to_file('https://ultralytics.com/images/zidane.jpg', 'zidane.jpg')
|
| 8 |
+
# torch.hub.download_url_to_file('https://ultralytics.com/images/bus.jpg', 'bus.jpg')
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def yolov8_predictor(img: gr.inputs.Image = None,
|
| 12 |
+
model_path: gr.inputs.Dropdown = None,
|
| 13 |
+
image_size= 640,
|
| 14 |
+
conf= 0.25,
|
| 15 |
+
iou= 0.7
|
| 16 |
+
):
|
| 17 |
+
|
| 18 |
+
model= YOLO(model= model_path)
|
| 19 |
+
res= model.predict(source= img, imgsz=image_size, conf= conf, iou= iou)
|
| 20 |
+
|
| 21 |
+
cls_names= res[0].names
|
| 22 |
+
dets_cls= res[0].boxes.cls.cpu().numpy().astype(int)
|
| 23 |
+
|
| 24 |
+
dets= [cls_names[i] for i in dets_cls]
|
| 25 |
+
dets= dict(Counter(dets))
|
| 26 |
+
res_plotted = res[0].plot()
|
| 27 |
+
res_plotted= cv2.cvtColor(res_plotted, cv2.COLOR_BGR2RGB)
|
| 28 |
+
|
| 29 |
+
return res_plotted, str(dets)
|
| 30 |
+
|
| 31 |
+
inputs = [
|
| 32 |
+
gr.inputs.Image(type="filepath", label="Input Image"),
|
| 33 |
+
gr.inputs.Dropdown(["yolov8n.pt", "yolov8s.pt"],
|
| 34 |
+
default="yolov8s.pt", label="Model"),
|
| 35 |
+
gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
|
| 36 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
|
| 37 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.7, step=0.05, label="IOU Threshold"),
|
| 38 |
+
]
|
| 39 |
+
|
| 40 |
+
outputs = [gr.outputs.Image(type="filepath", label="Output Image"), "text"]
|
| 41 |
+
title = "YOLOv8"
|
| 42 |
+
|
| 43 |
+
examples = [['zidane.jpg', 'yolov8s.pt', 640, 0.25, 0.7], ['bus.jpg', 'yolov8s.pt', 640, 0.25, 0.7]]
|
| 44 |
+
|
| 45 |
+
demo_app = gr.Interface(
|
| 46 |
+
fn=yolov8_predictor,
|
| 47 |
+
inputs=inputs,
|
| 48 |
+
outputs=outputs,
|
| 49 |
+
title=title,
|
| 50 |
+
examples=examples,
|
| 51 |
+
cache_examples=True,
|
| 52 |
+
theme='huggingface',
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
demo_app.launch(debug=True, enable_queue=True)
|
bus.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
opencv_python
|
| 2 |
+
torch
|
| 3 |
+
ultralytics==8.0.113
|
| 4 |
+
gradio_client==0.2.7
|
yolov8n.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:31e20dde3def09e2cf938c7be6fe23d9150bbbe503982af13345706515f2ef95
|
| 3 |
+
size 6534387
|
yolov8s.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:268e5bb54c640c96c3510224833bc2eeacab4135c6deb41502156e39986b562d
|
| 3 |
+
size 22573363
|
zidane.jpg
ADDED
|