Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- README.md +5 -4
- app.py +98 -0
- best.pt +3 -0
- gitattributes +35 -0
- requirements.txt +47 -0
README.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: red
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Pothole Detection
|
| 3 |
+
emoji: 🌍
|
| 4 |
colorFrom: red
|
| 5 |
+
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.6.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: apache-2.0
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import requests
|
| 4 |
+
import os
|
| 5 |
+
from ultralytics import YOLO
|
| 6 |
+
|
| 7 |
+
file_urls = [
|
| 8 |
+
'https://www.dropbox.com/s/b5g97xo901zb3ds/pothole_example.jpg?dl=1',
|
| 9 |
+
'https://www.dropbox.com/s/86uxlxxlm1iaexa/pothole_screenshot.png?dl=1',
|
| 10 |
+
'https://www.dropbox.com/s/7sjfwncffg8xej2/video_7.mp4?dl=1'
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
def download_file(url, save_name):
|
| 14 |
+
if not os.path.exists(save_name):
|
| 15 |
+
file = requests.get(url)
|
| 16 |
+
open(save_name, 'wb').write(file.content)
|
| 17 |
+
|
| 18 |
+
for i, url in enumerate(file_urls):
|
| 19 |
+
if 'mp4' in file_urls[i]:
|
| 20 |
+
download_file(file_urls[i], f"video.mp4")
|
| 21 |
+
else:
|
| 22 |
+
download_file(file_urls[i], f"image_{i}.jpg")
|
| 23 |
+
|
| 24 |
+
model = YOLO('best.pt')
|
| 25 |
+
path = [['image_0.jpg'], ['image_1.jpg']]
|
| 26 |
+
video_path = [['video.mp4']]
|
| 27 |
+
|
| 28 |
+
def show_preds_image(image_path):
|
| 29 |
+
image = cv2.imread(image_path)
|
| 30 |
+
outputs = model.predict(source=image_path)
|
| 31 |
+
results = outputs[0].cpu().numpy()
|
| 32 |
+
for det in results.boxes.xyxy:
|
| 33 |
+
cv2.rectangle(
|
| 34 |
+
image,
|
| 35 |
+
(int(det[0]), int(det[1])),
|
| 36 |
+
(int(det[2]), int(det[3])),
|
| 37 |
+
color=(0, 0, 255),
|
| 38 |
+
thickness=2,
|
| 39 |
+
lineType=cv2.LINE_AA
|
| 40 |
+
)
|
| 41 |
+
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 42 |
+
|
| 43 |
+
inputs_image = gr.Image(type="filepath", label="Input Image")
|
| 44 |
+
outputs_image = gr.Image(label="Output Image")
|
| 45 |
+
|
| 46 |
+
def show_preds_video(video_path):
|
| 47 |
+
output_path = "processed_video.mp4"
|
| 48 |
+
cap = cv2.VideoCapture(video_path)
|
| 49 |
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 50 |
+
out = cv2.VideoWriter(output_path, fourcc, cap.get(cv2.CAP_PROP_FPS),
|
| 51 |
+
(int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)), int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))))
|
| 52 |
+
|
| 53 |
+
while cap.isOpened():
|
| 54 |
+
ret, frame = cap.read()
|
| 55 |
+
if not ret:
|
| 56 |
+
break
|
| 57 |
+
outputs = model.predict(source=frame)
|
| 58 |
+
results = outputs[0].cpu().numpy()
|
| 59 |
+
for det in results.boxes.xyxy:
|
| 60 |
+
cv2.rectangle(
|
| 61 |
+
frame,
|
| 62 |
+
(int(det[0]), int(det[1])),
|
| 63 |
+
(int(det[2]), int(det[3])),
|
| 64 |
+
color=(0, 0, 255),
|
| 65 |
+
thickness=2,
|
| 66 |
+
lineType=cv2.LINE_AA
|
| 67 |
+
)
|
| 68 |
+
out.write(frame)
|
| 69 |
+
|
| 70 |
+
cap.release()
|
| 71 |
+
out.release()
|
| 72 |
+
return output_path
|
| 73 |
+
|
| 74 |
+
inputs_video = gr.Video(label="Input Video")
|
| 75 |
+
outputs_video = gr.Video(label="Output Video")
|
| 76 |
+
|
| 77 |
+
interface_image = gr.Interface(
|
| 78 |
+
fn=show_preds_image,
|
| 79 |
+
inputs=inputs_image,
|
| 80 |
+
outputs=outputs_image,
|
| 81 |
+
title="Pothole Detector App (Image)",
|
| 82 |
+
examples=path,
|
| 83 |
+
cache_examples=False,
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
interface_video = gr.Interface(
|
| 87 |
+
fn=show_preds_video,
|
| 88 |
+
inputs=inputs_video,
|
| 89 |
+
outputs=outputs_video,
|
| 90 |
+
title="Pothole Detector App (Video)",
|
| 91 |
+
examples=video_path,
|
| 92 |
+
cache_examples=False,
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
gr.TabbedInterface(
|
| 96 |
+
[interface_image, interface_video],
|
| 97 |
+
tab_names=['Image Inference', 'Video Inference']
|
| 98 |
+
).queue().launch()
|
best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ce9a23590d666fcca004d3a2330f3e30b229bbe9df0dbf4b0fd390c20fbe67fe
|
| 3 |
+
size 6233272
|
gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
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
|