Spaces:
Runtime error
Runtime error
lets see
Browse files
app.py
CHANGED
@@ -2,33 +2,34 @@ from ultralytics import YOLO
|
|
2 |
import gradio as gr
|
3 |
import cv2
|
4 |
import os
|
|
|
5 |
|
6 |
model = YOLO('best.pt')
|
7 |
|
8 |
|
9 |
def show_preds_image(image_path):
|
10 |
image = cv2.imread(image_path)
|
11 |
-
outputs = model.predict(source=image_path)
|
12 |
print("output:", outputs)
|
13 |
results = outputs[0]
|
14 |
print("results:", results)
|
15 |
|
16 |
-
for i, det in enumerate(results.boxes.xyxy.cpu().numpy()):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
return
|
26 |
|
27 |
inputs_image = [
|
28 |
gr.components.Image(type="filepath", label="Input Image"),
|
29 |
]
|
30 |
outputs_image = [
|
31 |
-
gr.components.Image(type="
|
32 |
]
|
33 |
interface_image = gr.Interface(
|
34 |
fn=show_preds_image,
|
@@ -45,14 +46,14 @@ def show_preds_video(video_path):
|
|
45 |
ret, frame = cap.read()
|
46 |
if ret:
|
47 |
frame_copy = frame.copy()
|
48 |
-
outputs = model.predict(source=frame)
|
49 |
results = outputs[0]
|
50 |
for i, det in enumerate(results.boxes.xyxy.cpu().numpy()):
|
51 |
cv2.rectangle(
|
52 |
frame_copy,
|
53 |
(int(det[0]), int(det[1])),
|
54 |
(int(det[2]), int(det[3])),
|
55 |
-
color=(0, 0, 255),
|
56 |
thickness=2,
|
57 |
lineType=cv2.LINE_AA
|
58 |
)
|
|
|
2 |
import gradio as gr
|
3 |
import cv2
|
4 |
import os
|
5 |
+
import random
|
6 |
|
7 |
model = YOLO('best.pt')
|
8 |
|
9 |
|
10 |
def show_preds_image(image_path):
|
11 |
image = cv2.imread(image_path)
|
12 |
+
outputs = model.predict(source=image_path, conf=0.45, save=True)
|
13 |
print("output:", outputs)
|
14 |
results = outputs[0]
|
15 |
print("results:", results)
|
16 |
|
17 |
+
# for i, det in enumerate(results.boxes.xyxy.cpu().numpy()):
|
18 |
+
# cv2.rectangle(
|
19 |
+
# image,
|
20 |
+
# (int(det[0]), int(det[1])),
|
21 |
+
# (int(det[2]), int(det[3])),
|
22 |
+
# color=(random.randint(0,255), random.randint(0,255), random.randint(0,255)),
|
23 |
+
# thickness=2,
|
24 |
+
# lineType=cv2.LINE_AA
|
25 |
+
# )
|
26 |
+
return f"runs/detect/predict/{os.path.split(image_path)[-1]}"
|
27 |
|
28 |
inputs_image = [
|
29 |
gr.components.Image(type="filepath", label="Input Image"),
|
30 |
]
|
31 |
outputs_image = [
|
32 |
+
gr.components.Image(type="filepath", label="Output Image"),
|
33 |
]
|
34 |
interface_image = gr.Interface(
|
35 |
fn=show_preds_image,
|
|
|
46 |
ret, frame = cap.read()
|
47 |
if ret:
|
48 |
frame_copy = frame.copy()
|
49 |
+
outputs = model.predict(source=frame, conf=0.45)
|
50 |
results = outputs[0]
|
51 |
for i, det in enumerate(results.boxes.xyxy.cpu().numpy()):
|
52 |
cv2.rectangle(
|
53 |
frame_copy,
|
54 |
(int(det[0]), int(det[1])),
|
55 |
(int(det[2]), int(det[3])),
|
56 |
+
color=(random.randint(0,255), random.randint(0,255), random.randint(0,255)),
|
57 |
thickness=2,
|
58 |
lineType=cv2.LINE_AA
|
59 |
)
|