Spaces:
Running
Running
worked on app
Browse files- .gitignore +5 -0
- app.py +59 -0
- requirements.txt +47 -0
.gitignore
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
flagged/
|
2 |
+
*.pt
|
3 |
+
*.png
|
4 |
+
*.jpg
|
5 |
+
gradio_cached_examples/
|
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import requests
|
4 |
+
import os
|
5 |
+
|
6 |
+
import torch
|
7 |
+
import ultralytics
|
8 |
+
|
9 |
+
file_urls = [
|
10 |
+
'https://www.dropbox.com/s/bc9r8n7919cbc77/test-image.jpg?dl=0',
|
11 |
+
'https://www.dropbox.com/s/fkmzgdm6okdzxdk/test-image-2.jpg?dl=0',
|
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)
|
19 |
+
|
20 |
+
for i, url in enumerate(file_urls):
|
21 |
+
download_file(
|
22 |
+
file_urls[i],
|
23 |
+
f"image_{i}.jpg"
|
24 |
+
)
|
25 |
+
|
26 |
+
model = torch.hub.load("ultralytics/yolov5", "custom", path="../yolov5_0.65map_exp7_best.pt",
|
27 |
+
force_reload=False)
|
28 |
+
|
29 |
+
path = [['image_0.jpg'], ['image_1.jpg']]
|
30 |
+
|
31 |
+
def show_preds_image(image_path):
|
32 |
+
image = cv2.imread(image_path)
|
33 |
+
outputs = model.predict(source=image_path)
|
34 |
+
results = outputs[0].cpu().numpy()
|
35 |
+
for i, det in enumerate(results.boxes.xyxy):
|
36 |
+
cv2.rectangle(
|
37 |
+
image,
|
38 |
+
(int(det[0]), int(det[1])),
|
39 |
+
(int(det[2]), int(det[3])),
|
40 |
+
color=(0, 0, 255),
|
41 |
+
thickness=2,
|
42 |
+
lineType=cv2.LINE_AA
|
43 |
+
)
|
44 |
+
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
45 |
+
|
46 |
+
inputs_image = [
|
47 |
+
gr.components.Image(type="filepath", label="Input Image"),
|
48 |
+
]
|
49 |
+
outputs_image = [
|
50 |
+
gr.components.Image(type="numpy", label="Output Image"),
|
51 |
+
]
|
52 |
+
interface_image = gr.Interface(
|
53 |
+
fn=show_preds_image,
|
54 |
+
inputs=inputs_image,
|
55 |
+
outputs=outputs_image,
|
56 |
+
title="Pothole detector",
|
57 |
+
examples=path,
|
58 |
+
cache_examples=False,
|
59 |
+
)
|
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
|