KaustubhK94 commited on
Commit
0f10495
1 Parent(s): 9b5d941

initial commit

Browse files
Files changed (3) hide show
  1. .gitignore +7 -0
  2. app.py +105 -0
  3. requirements.txt +47 -0
.gitignore ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ flagged/
2
+ *.pt
3
+ *.png
4
+ *.jpg
5
+ *.mp4
6
+ *.mkv
7
+ gradio_cached_examples/
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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://drive.google.com/file/d/1EZRZOvno2LeHVgBzDd1yGSKZcHpjvazT/view?usp=drive_link',
10
+ 'https://drive.google.com/file/d/1WHLbEZPCzYHTfvFeH2r58Au5fqz_n5rj/view?usp=drive_link',
11
+ 'https://drive.google.com/file/d/1RUpwU3Qe4Q2DSfu6bE9OEZiDfI--a_8y/view?usp=drive_link'
12
+
13
+ ]
14
+
15
+ def download_file(url, save_name):
16
+ url = url
17
+ if not os.path.exists(save_name):
18
+ file = requests.get(url)
19
+ open(save_name, 'wb').write(file.content)
20
+
21
+ for i, url in enumerate(file_urls):
22
+ if 'mp4' in file_urls[i]:
23
+ download_file(
24
+ file_urls[i],
25
+ f"video.mp4"
26
+ )
27
+ else:
28
+ download_file(
29
+ file_urls[i],
30
+ f"image_{i}.jpg"
31
+ )
32
+
33
+ model = YOLO('best.pt')
34
+ path = [['image_0.jpg'], ['image_1.jpg']]
35
+ video_path = [['video.mp4']]
36
+
37
+ def show_preds_image(image_path):
38
+ image = cv2.imread(image_path)
39
+ outputs = model.predict(source=image_path)
40
+ results = outputs[0].cpu().numpy()
41
+ for i, det in enumerate(results.boxes.xyxy):
42
+ cv2.rectangle(
43
+ image,
44
+ (int(det[0]), int(det[1])),
45
+ (int(det[2]), int(det[3])),
46
+ color=(0, 0, 255),
47
+ thickness=2,
48
+ lineType=cv2.LINE_AA
49
+ )
50
+ return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
51
+
52
+ inputs_image = [
53
+ gr.components.Image(type="filepath", label="Input Image"),
54
+ ]
55
+ outputs_image = [
56
+ gr.components.Image(type="numpy", label="Output Image"),
57
+ ]
58
+ interface_image = gr.Interface(
59
+ fn=show_preds_image,
60
+ inputs=inputs_image,
61
+ outputs=outputs_image,
62
+ title="Numberplate detector",
63
+ examples=path,
64
+ cache_examples=False,
65
+ )
66
+
67
+ def show_preds_video(video_path):
68
+ cap = cv2.VideoCapture(video_path)
69
+ while(cap.isOpened()):
70
+ ret, frame = cap.read()
71
+ if ret:
72
+ frame_copy = frame.copy()
73
+ outputs = model.predict(source=frame)
74
+ results = outputs[0].cpu().numpy()
75
+ for i, det in enumerate(results.boxes.xyxy):
76
+ cv2.rectangle(
77
+ frame_copy,
78
+ (int(det[0]), int(det[1])),
79
+ (int(det[2]), int(det[3])),
80
+ color=(0, 0, 255),
81
+ thickness=2,
82
+ lineType=cv2.LINE_AA
83
+ )
84
+ yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
85
+
86
+ inputs_video = [
87
+ gr.components.Video(type="filepath", label="Input Video"),
88
+
89
+ ]
90
+ outputs_video = [
91
+ gr.components.Image(type="numpy", label="Output Image"),
92
+ ]
93
+ interface_video = gr.Interface(
94
+ fn=show_preds_video,
95
+ inputs=inputs_video,
96
+ outputs=outputs_video,
97
+ title="Numberplate detector",
98
+ examples=video_path,
99
+ cache_examples=False,
100
+ )
101
+
102
+ gr.TabbedInterface(
103
+ [interface_image, interface_video],
104
+ tab_names=['Image inference', 'Video inference']
105
+ ).queue().launch()
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