Spaces:
Running
Running
initial commit
Browse files- app.py +79 -0
- best.pt +3 -0
- requirements.txt +47 -0
app.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
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 |
+
results = outputs[0].cpu().numpy()
|
13 |
+
for i, det in enumerate(results.boxes.xyxy):
|
14 |
+
cv2.rectangle(
|
15 |
+
image,
|
16 |
+
(int(det[0]), int(det[1])),
|
17 |
+
(int(det[2]), int(det[3])),
|
18 |
+
color=(0, 0, 255),
|
19 |
+
thickness=2,
|
20 |
+
lineType=cv2.LINE_AA
|
21 |
+
)
|
22 |
+
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
23 |
+
|
24 |
+
inputs_image = [
|
25 |
+
gr.components.Image(type="filepath", label="Input Image"),
|
26 |
+
]
|
27 |
+
outputs_image = [
|
28 |
+
gr.components.Image(type="numpy", label="Output Image"),
|
29 |
+
]
|
30 |
+
interface_image = gr.Interface(
|
31 |
+
fn=show_preds_image,
|
32 |
+
inputs=inputs_image,
|
33 |
+
outputs=outputs_image,
|
34 |
+
title="Pothole detector",
|
35 |
+
examples=path,
|
36 |
+
cache_examples=False,
|
37 |
+
)
|
38 |
+
|
39 |
+
|
40 |
+
def show_preds_video(video_path):
|
41 |
+
cap = cv2.VideoCapture(video_path)
|
42 |
+
while(cap.isOpened()):
|
43 |
+
ret, frame = cap.read()
|
44 |
+
if ret:
|
45 |
+
frame_copy = frame.copy()
|
46 |
+
outputs = model.predict(source=frame)
|
47 |
+
results = outputs[0].cpu().numpy()
|
48 |
+
for i, det in enumerate(results.boxes.xyxy):
|
49 |
+
cv2.rectangle(
|
50 |
+
frame_copy,
|
51 |
+
(int(det[0]), int(det[1])),
|
52 |
+
(int(det[2]), int(det[3])),
|
53 |
+
color=(0, 0, 255),
|
54 |
+
thickness=2,
|
55 |
+
lineType=cv2.LINE_AA
|
56 |
+
)
|
57 |
+
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
58 |
+
|
59 |
+
inputs_video = [
|
60 |
+
gr.components.Video(type="filepath", label="Input Video"),
|
61 |
+
|
62 |
+
]
|
63 |
+
outputs_video = [
|
64 |
+
gr.components.Image(type="numpy", label="Output Image"),
|
65 |
+
]
|
66 |
+
interface_video = gr.Interface(
|
67 |
+
fn=show_preds_video,
|
68 |
+
inputs=inputs_video,
|
69 |
+
outputs=outputs_video,
|
70 |
+
title="Pothole detector",
|
71 |
+
examples=video_path,
|
72 |
+
cache_examples=False,
|
73 |
+
)
|
74 |
+
|
75 |
+
|
76 |
+
gr.TabbedInterface(
|
77 |
+
[interface_image, interface_video],
|
78 |
+
tab_names=['Image inference', 'Video inference']
|
79 |
+
).queue().launch()
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:15cb48c34378d663ab90581c9df00400386823592d38e8e8ef837f55a880a5e9
|
3 |
+
size 136696008
|
requirements.txt
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Ultralytics requirements
|
2 |
+
# Usage: pip install -r requirements.txt
|
3 |
+
|
4 |
+
# Base ----------------------------------------
|
5 |
+
hydra-core>=1.2.0
|
6 |
+
matplotlib>=3.2.2
|
7 |
+
numpy>=1.18.5
|
8 |
+
opencv-python>=4.1.1
|
9 |
+
Pillow>=7.1.2
|
10 |
+
PyYAML>=5.3.1
|
11 |
+
requests>=2.23.0
|
12 |
+
scipy>=1.4.1
|
13 |
+
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
|
30 |
+
# onnx-simplifier>=0.4.1 # ONNX simplifier
|
31 |
+
# nvidia-pyindex # TensorRT export
|
32 |
+
# nvidia-tensorrt # TensorRT export
|
33 |
+
# scikit-learn==0.19.2 # CoreML quantization
|
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
|
41 |
+
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
|