dwkurnie
commited on
Commit
·
6da4103
1
Parent(s):
89fbcb1
update
Browse files- .gitignore +1 -1
- 1.jpeg +0 -0
- 2.jpeg +0 -0
- app.py +44 -27
- requirements.txt +7 -7
.gitignore
CHANGED
@@ -3,4 +3,4 @@ flagged/
|
|
3 |
*.jpg
|
4 |
*.mp4
|
5 |
*.mkv
|
6 |
-
gradio_cached_examples/
|
|
|
3 |
*.jpg
|
4 |
*.mp4
|
5 |
*.mkv
|
6 |
+
# gradio_cached_examples/
|
1.jpeg
ADDED
2.jpeg
ADDED
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import cv2
|
3 |
import requests
|
4 |
import os
|
|
|
5 |
|
6 |
from ultralytics import YOLO
|
7 |
|
@@ -12,7 +13,6 @@ file_urls = [
|
|
12 |
]
|
13 |
|
14 |
def download_file(url, save_name):
|
15 |
-
url = url
|
16 |
if not os.path.exists(save_name):
|
17 |
file = requests.get(url)
|
18 |
open(save_name, 'wb').write(file.content)
|
@@ -30,8 +30,8 @@ for i, url in enumerate(file_urls):
|
|
30 |
)
|
31 |
|
32 |
model = YOLO('best.pt')
|
33 |
-
path = [['
|
34 |
-
video_path = [['
|
35 |
|
36 |
def show_preds_image(image_path):
|
37 |
image = cv2.imread(image_path)
|
@@ -48,21 +48,6 @@ def show_preds_image(image_path):
|
|
48 |
)
|
49 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
50 |
|
51 |
-
inputs_image = [
|
52 |
-
gr.components.Image(type="filepath", label="Input Image"),
|
53 |
-
]
|
54 |
-
outputs_image = [
|
55 |
-
gr.components.Image(type="numpy", label="Output Image"),
|
56 |
-
]
|
57 |
-
interface_image = gr.Interface(
|
58 |
-
fn=show_preds_image,
|
59 |
-
inputs=inputs_image,
|
60 |
-
outputs=outputs_image,
|
61 |
-
title="Pothole detector app",
|
62 |
-
examples=path,
|
63 |
-
cache_examples=False,
|
64 |
-
)
|
65 |
-
|
66 |
def show_preds_video(video_path):
|
67 |
cap = cv2.VideoCapture(video_path)
|
68 |
while(cap.isOpened()):
|
@@ -81,14 +66,37 @@ def show_preds_video(video_path):
|
|
81 |
lineType=cv2.LINE_AA
|
82 |
)
|
83 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
-
|
89 |
-
outputs_video =
|
90 |
-
gr.components.Image(type="numpy", label="Output Image"),
|
91 |
-
]
|
92 |
interface_video = gr.Interface(
|
93 |
fn=show_preds_video,
|
94 |
inputs=inputs_video,
|
@@ -98,7 +106,16 @@ interface_video = gr.Interface(
|
|
98 |
cache_examples=False,
|
99 |
)
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
gr.TabbedInterface(
|
102 |
-
[interface_image, interface_video],
|
103 |
-
tab_names=['Image
|
104 |
-
).queue().launch()
|
|
|
2 |
import cv2
|
3 |
import requests
|
4 |
import os
|
5 |
+
import numpy as np
|
6 |
|
7 |
from ultralytics import YOLO
|
8 |
|
|
|
13 |
]
|
14 |
|
15 |
def download_file(url, save_name):
|
|
|
16 |
if not os.path.exists(save_name):
|
17 |
file = requests.get(url)
|
18 |
open(save_name, 'wb').write(file.content)
|
|
|
30 |
)
|
31 |
|
32 |
model = YOLO('best.pt')
|
33 |
+
path = [['1.jpeg'], ['2.jpeg']]
|
34 |
+
video_path = [['contoh.mp4']]
|
35 |
|
36 |
def show_preds_image(image_path):
|
37 |
image = cv2.imread(image_path)
|
|
|
48 |
)
|
49 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
def show_preds_video(video_path):
|
52 |
cap = cv2.VideoCapture(video_path)
|
53 |
while(cap.isOpened()):
|
|
|
66 |
lineType=cv2.LINE_AA
|
67 |
)
|
68 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
69 |
+
else:
|
70 |
+
break
|
71 |
+
|
72 |
+
def show_preds_webcam(frame):
|
73 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
74 |
+
outputs = model.predict(source=frame)
|
75 |
+
results = outputs[0].cpu().numpy()
|
76 |
+
for i, det in enumerate(results.boxes.xyxy):
|
77 |
+
cv2.rectangle(
|
78 |
+
frame,
|
79 |
+
(int(det[0]), int(det[1])),
|
80 |
+
(int(det[2]), int(det[3])),
|
81 |
+
color=(0, 0, 255),
|
82 |
+
thickness=2,
|
83 |
+
lineType=cv2.LINE_AA
|
84 |
+
)
|
85 |
+
return frame
|
86 |
|
87 |
+
inputs_image = gr.Image(label="Input Image")
|
88 |
+
outputs_image = gr.Image(label="Output Image")
|
89 |
+
interface_image = gr.Interface(
|
90 |
+
fn=show_preds_image,
|
91 |
+
inputs=inputs_image,
|
92 |
+
outputs=outputs_image,
|
93 |
+
title="Pothole detector",
|
94 |
+
examples=path,
|
95 |
+
cache_examples=False,
|
96 |
+
)
|
97 |
|
98 |
+
inputs_video = gr.Video(label="Input Video")
|
99 |
+
outputs_video = gr.Image(label="Output Image")
|
|
|
|
|
100 |
interface_video = gr.Interface(
|
101 |
fn=show_preds_video,
|
102 |
inputs=inputs_video,
|
|
|
106 |
cache_examples=False,
|
107 |
)
|
108 |
|
109 |
+
inputs_webcam = gr.Image(sources="webcam", streaming=True)
|
110 |
+
outputs_webcam = gr.Image(label="Output Image")
|
111 |
+
interface_webcam = gr.Interface(
|
112 |
+
fn=show_preds_webcam,
|
113 |
+
inputs=inputs_webcam,
|
114 |
+
outputs=outputs_webcam,
|
115 |
+
title="Webcam Object Detection"
|
116 |
+
)
|
117 |
+
|
118 |
gr.TabbedInterface(
|
119 |
+
[interface_image, interface_video, interface_webcam],
|
120 |
+
tab_names=['Image Inference', 'Video Inference', 'Webcam Inference']
|
121 |
+
).queue().launch()
|
requirements.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
# Ultralytics requirements
|
2 |
# Usage: pip install -r requirements.txt
|
3 |
-
|
4 |
# Base ----------------------------------------
|
5 |
hydra-core>=1.2.0
|
6 |
matplotlib>=3.2.2
|
@@ -14,16 +14,16 @@ torch>=1.7.0
|
|
14 |
torchvision>=0.8.1
|
15 |
tqdm>=4.64.0
|
16 |
ultralytics
|
17 |
-
|
18 |
# Logging -------------------------------------
|
19 |
tensorboard>=2.4.1
|
20 |
# clearml
|
21 |
# comet
|
22 |
-
|
23 |
# Plotting ------------------------------------
|
24 |
pandas>=1.1.4
|
25 |
seaborn>=0.11.0
|
26 |
-
|
27 |
# Export --------------------------------------
|
28 |
# coremltools>=6.0 # CoreML export
|
29 |
# onnx>=1.12.0 # ONNX export
|
@@ -34,7 +34,7 @@ seaborn>=0.11.0
|
|
34 |
# tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos)
|
35 |
# tensorflowjs>=3.9.0 # TF.js export
|
36 |
# openvino-dev # OpenVINO export
|
37 |
-
|
38 |
# Extras --------------------------------------
|
39 |
ipython # interactive notebook
|
40 |
psutil # system utilization
|
@@ -42,6 +42,6 @@ thop>=0.1.1 # FLOPs computation
|
|
42 |
# albumentations>=1.0.3
|
43 |
# pycocotools>=2.0.6 # COCO mAP
|
44 |
# roboflow
|
45 |
-
|
46 |
# HUB -----------------------------------------
|
47 |
-
GitPython>=3.1.24
|
|
|
1 |
# Ultralytics requirements
|
2 |
# Usage: pip install -r requirements.txt
|
3 |
+
|
4 |
# Base ----------------------------------------
|
5 |
hydra-core>=1.2.0
|
6 |
matplotlib>=3.2.2
|
|
|
14 |
torchvision>=0.8.1
|
15 |
tqdm>=4.64.0
|
16 |
ultralytics
|
17 |
+
|
18 |
# Logging -------------------------------------
|
19 |
tensorboard>=2.4.1
|
20 |
# clearml
|
21 |
# comet
|
22 |
+
|
23 |
# Plotting ------------------------------------
|
24 |
pandas>=1.1.4
|
25 |
seaborn>=0.11.0
|
26 |
+
|
27 |
# Export --------------------------------------
|
28 |
# coremltools>=6.0 # CoreML export
|
29 |
# onnx>=1.12.0 # ONNX export
|
|
|
34 |
# tensorflow>=2.4.1 # TF exports (-cpu, -aarch64, -macos)
|
35 |
# tensorflowjs>=3.9.0 # TF.js export
|
36 |
# openvino-dev # OpenVINO export
|
37 |
+
|
38 |
# Extras --------------------------------------
|
39 |
ipython # interactive notebook
|
40 |
psutil # system utilization
|
|
|
42 |
# albumentations>=1.0.3
|
43 |
# pycocotools>=2.0.6 # COCO mAP
|
44 |
# roboflow
|
45 |
+
|
46 |
# HUB -----------------------------------------
|
47 |
+
GitPython>=3.1.24
|