Spaces:
Sleeping
Sleeping
Commit
·
2051493
1
Parent(s):
fdc23ca
added gradio demo
Browse files- app.py +27 -0
- best.pt +3 -0
- example1.jpg +0 -0
- example2.jpg +0 -0
- example3.jpg +0 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics import YOLO
|
2 |
+
from ultralytics.utils.plotting import Annotator
|
3 |
+
import torch
|
4 |
+
import gradio as gr
|
5 |
+
import cv2
|
6 |
+
model = YOLO('best.pt')
|
7 |
+
def yolo_pred(image):
|
8 |
+
result = model.predict(image)[0]
|
9 |
+
annotator = Annotator(result.orig_img)
|
10 |
+
color_list = [(107, 31, 45), (32, 102, 50), (32, 45, 102)]
|
11 |
+
for label in result.boxes.data.detach().numpy():
|
12 |
+
annotator.box_label(
|
13 |
+
label[0:4],
|
14 |
+
str(result.names[label[-1].item()]) + " " + str(round(label[-2], 2)),
|
15 |
+
color_list[int(label[-1].item())]
|
16 |
+
)
|
17 |
+
print(round(label[-2], 2))
|
18 |
+
return annotator.im
|
19 |
+
gr.Interface(fn=yolo_pred,
|
20 |
+
inputs="image",
|
21 |
+
outputs="image",
|
22 |
+
examples=[
|
23 |
+
[cv2.imread("example1.jpg")],
|
24 |
+
[cv2.imread("example2.jpg")],
|
25 |
+
[cv2.imread("example3.jpg")],
|
26 |
+
]
|
27 |
+
).launch()
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cf47a92c317e706a8bfbea42a92455dbae93c500c373471f044487ba685faedc
|
3 |
+
size 6262115
|
example1.jpg
ADDED
![]() |
example2.jpg
ADDED
![]() |
example3.jpg
ADDED
![]() |
requirements.txt
ADDED
Binary file (7.04 kB). View file
|
|