rajsecrets0 commited on
Commit
cdf8301
1 Parent(s): 11a752e

Upload 5 files

Browse files
Files changed (5) hide show
  1. README.md +5 -5
  2. app.py +104 -0
  3. gitattributes.txt +34 -0
  4. gitignore.txt +7 -0
  5. requirements.txt +47 -0
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Potholes
3
- emoji: 🦀
4
- colorFrom: indigo
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 4.8.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
1
  ---
2
+ title: Pothole Yolov8 Nano
3
+ emoji: 🌖
4
+ colorFrom: pink
5
+ colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 3.16.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import requests
4
+ import os
5
+
6
+ from ultralytics import YOLO
7
+
8
+ file_urls = [
9
+ 'https://www.dropbox.com/s/b5g97xo901zb3ds/pothole_example.jpg?dl=1',
10
+ 'https://www.dropbox.com/s/86uxlxxlm1iaexa/pothole_screenshot.png?dl=1',
11
+ 'https://www.dropbox.com/s/7sjfwncffg8xej2/video_7.mp4?dl=1'
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
+ if 'mp4' in file_urls[i]:
22
+ download_file(
23
+ file_urls[i],
24
+ f"video.mp4"
25
+ )
26
+ else:
27
+ download_file(
28
+ file_urls[i],
29
+ f"image_{i}.jpg"
30
+ )
31
+
32
+ model = YOLO('best.pt')
33
+ path = [['image_0.jpg'], ['image_1.jpg']]
34
+ video_path = [['video.mp4']]
35
+
36
+ def show_preds_image(image_path):
37
+ image = cv2.imread(image_path)
38
+ outputs = model.predict(source=image_path)
39
+ results = outputs[0].cpu().numpy()
40
+ for i, det in enumerate(results.boxes.xyxy):
41
+ cv2.rectangle(
42
+ image,
43
+ (int(det[0]), int(det[1])),
44
+ (int(det[2]), int(det[3])),
45
+ color=(0, 0, 255),
46
+ thickness=2,
47
+ lineType=cv2.LINE_AA
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",
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()):
69
+ ret, frame = cap.read()
70
+ if ret:
71
+ frame_copy = frame.copy()
72
+ outputs = model.predict(source=frame)
73
+ results = outputs[0].cpu().numpy()
74
+ for i, det in enumerate(results.boxes.xyxy):
75
+ cv2.rectangle(
76
+ frame_copy,
77
+ (int(det[0]), int(det[1])),
78
+ (int(det[2]), int(det[3])),
79
+ color=(0, 0, 255),
80
+ thickness=2,
81
+ lineType=cv2.LINE_AA
82
+ )
83
+ yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
84
+
85
+ inputs_video = [
86
+ gr.components.Video(type="filepath", label="Input Video"),
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,
95
+ outputs=outputs_video,
96
+ title="Pothole detector",
97
+ examples=video_path,
98
+ cache_examples=False,
99
+ )
100
+
101
+ gr.TabbedInterface(
102
+ [interface_image, interface_video],
103
+ tab_names=['Image inference', 'Video inference']
104
+ ).queue().launch()
gitattributes.txt ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
gitignore.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ flagged/
2
+ *.pt
3
+ *.png
4
+ *.jpg
5
+ *.mp4
6
+ *.mkv
7
+ gradio_cached_examples/
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