Skip to content

Commit 6e453ef

Browse files
author
Asadullah-Dal17
committed
adding object detection code and weights files
0 parents  commit 6e453ef

File tree

3 files changed

+338
-0
lines changed

3 files changed

+338
-0
lines changed

yolov4-tiny.cfg

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
[net]
2+
# Testing
3+
#batch=1
4+
#subdivisions=1
5+
# Training
6+
batch=64
7+
subdivisions=1
8+
width=416
9+
height=416
10+
channels=3
11+
momentum=0.9
12+
decay=0.0005
13+
angle=0
14+
saturation = 1.5
15+
exposure = 1.5
16+
hue=.1
17+
18+
learning_rate=0.00261
19+
burn_in=1000
20+
21+
max_batches = 2000200
22+
policy=steps
23+
steps=1600000,1800000
24+
scales=.1,.1
25+
26+
27+
#weights_reject_freq=1001
28+
#ema_alpha=0.9998
29+
#equidistant_point=1000
30+
#num_sigmas_reject_badlabels=3
31+
#badlabels_rejection_percentage=0.2
32+
33+
34+
[convolutional]
35+
batch_normalize=1
36+
filters=32
37+
size=3
38+
stride=2
39+
pad=1
40+
activation=leaky
41+
42+
[convolutional]
43+
batch_normalize=1
44+
filters=64
45+
size=3
46+
stride=2
47+
pad=1
48+
activation=leaky
49+
50+
[convolutional]
51+
batch_normalize=1
52+
filters=64
53+
size=3
54+
stride=1
55+
pad=1
56+
activation=leaky
57+
58+
[route]
59+
layers=-1
60+
groups=2
61+
group_id=1
62+
63+
[convolutional]
64+
batch_normalize=1
65+
filters=32
66+
size=3
67+
stride=1
68+
pad=1
69+
activation=leaky
70+
71+
[convolutional]
72+
batch_normalize=1
73+
filters=32
74+
size=3
75+
stride=1
76+
pad=1
77+
activation=leaky
78+
79+
[route]
80+
layers = -1,-2
81+
82+
[convolutional]
83+
batch_normalize=1
84+
filters=64
85+
size=1
86+
stride=1
87+
pad=1
88+
activation=leaky
89+
90+
[route]
91+
layers = -6,-1
92+
93+
[maxpool]
94+
size=2
95+
stride=2
96+
97+
[convolutional]
98+
batch_normalize=1
99+
filters=128
100+
size=3
101+
stride=1
102+
pad=1
103+
activation=leaky
104+
105+
[route]
106+
layers=-1
107+
groups=2
108+
group_id=1
109+
110+
[convolutional]
111+
batch_normalize=1
112+
filters=64
113+
size=3
114+
stride=1
115+
pad=1
116+
activation=leaky
117+
118+
[convolutional]
119+
batch_normalize=1
120+
filters=64
121+
size=3
122+
stride=1
123+
pad=1
124+
activation=leaky
125+
126+
[route]
127+
layers = -1,-2
128+
129+
[convolutional]
130+
batch_normalize=1
131+
filters=128
132+
size=1
133+
stride=1
134+
pad=1
135+
activation=leaky
136+
137+
[route]
138+
layers = -6,-1
139+
140+
[maxpool]
141+
size=2
142+
stride=2
143+
144+
[convolutional]
145+
batch_normalize=1
146+
filters=256
147+
size=3
148+
stride=1
149+
pad=1
150+
activation=leaky
151+
152+
[route]
153+
layers=-1
154+
groups=2
155+
group_id=1
156+
157+
[convolutional]
158+
batch_normalize=1
159+
filters=128
160+
size=3
161+
stride=1
162+
pad=1
163+
activation=leaky
164+
165+
[convolutional]
166+
batch_normalize=1
167+
filters=128
168+
size=3
169+
stride=1
170+
pad=1
171+
activation=leaky
172+
173+
[route]
174+
layers = -1,-2
175+
176+
[convolutional]
177+
batch_normalize=1
178+
filters=256
179+
size=1
180+
stride=1
181+
pad=1
182+
activation=leaky
183+
184+
[route]
185+
layers = -6,-1
186+
187+
[maxpool]
188+
size=2
189+
stride=2
190+
191+
[convolutional]
192+
batch_normalize=1
193+
filters=512
194+
size=3
195+
stride=1
196+
pad=1
197+
activation=leaky
198+
199+
##################################
200+
201+
[convolutional]
202+
batch_normalize=1
203+
filters=256
204+
size=1
205+
stride=1
206+
pad=1
207+
activation=leaky
208+
209+
[convolutional]
210+
batch_normalize=1
211+
filters=512
212+
size=3
213+
stride=1
214+
pad=1
215+
activation=leaky
216+
217+
[convolutional]
218+
size=1
219+
stride=1
220+
pad=1
221+
filters=255
222+
activation=linear
223+
224+
225+
226+
[yolo]
227+
mask = 3,4,5
228+
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
229+
classes=80
230+
num=6
231+
jitter=.3
232+
scale_x_y = 1.05
233+
cls_normalizer=1.0
234+
iou_normalizer=0.07
235+
iou_loss=ciou
236+
ignore_thresh = .7
237+
truth_thresh = 1
238+
random=0
239+
resize=1.5
240+
nms_kind=greedynms
241+
beta_nms=0.6
242+
#new_coords=1
243+
#scale_x_y = 2.0
244+
245+
[route]
246+
layers = -4
247+
248+
[convolutional]
249+
batch_normalize=1
250+
filters=128
251+
size=1
252+
stride=1
253+
pad=1
254+
activation=leaky
255+
256+
[upsample]
257+
stride=2
258+
259+
[route]
260+
layers = -1, 23
261+
262+
[convolutional]
263+
batch_normalize=1
264+
filters=256
265+
size=3
266+
stride=1
267+
pad=1
268+
activation=leaky
269+
270+
[convolutional]
271+
size=1
272+
stride=1
273+
pad=1
274+
filters=255
275+
activation=linear
276+
277+
[yolo]
278+
mask = 1,2,3
279+
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
280+
classes=80
281+
num=6
282+
jitter=.3
283+
scale_x_y = 1.05
284+
cls_normalizer=1.0
285+
iou_normalizer=0.07
286+
iou_loss=ciou
287+
ignore_thresh = .7
288+
truth_thresh = 1
289+
random=0
290+
resize=1.5
291+
nms_kind=greedynms
292+
beta_nms=0.6
293+
#new_coords=1
294+
#scale_x_y = 2.0

yolov4-tiny.weights

23.1 MB
Binary file not shown.

yolov4.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import cv2
2+
import time
3+
4+
CONFIDENCE_THRESHOLD = 0.2
5+
NMS_THRESHOLD = 0.4
6+
COLORS = [(0, 255, 255), (255, 255, 0), (0, 255, 0), (255, 0, 0)]
7+
8+
class_names = []
9+
with open("classes.txt", "r") as f:
10+
class_names = [cname.strip() for cname in f.readlines()]
11+
12+
vc = cv2.VideoCapture(0)
13+
14+
net = cv2.dnn.readNet("yolov4-tiny.weights", "yolov4-tiny.cfg")
15+
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
16+
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA_FP16)
17+
18+
model = cv2.dnn_DetectionModel(net)
19+
model.setInputParams(size=(416, 416), scale=1/255, swapRB=True)
20+
21+
while cv2.waitKey(1) < 1:
22+
(grabbed, frame) = vc.read()
23+
if not grabbed:
24+
exit()
25+
26+
start = time.time()
27+
classes, scores, boxes = model.detect(
28+
frame, CONFIDENCE_THRESHOLD, NMS_THRESHOLD)
29+
end = time.time()
30+
31+
start_drawing = time.time()
32+
for (classid, score, box) in zip(classes, scores, boxes):
33+
color = COLORS[int(classid) % len(COLORS)]
34+
label = "%s : %f" % (class_names[classid[0]], score)
35+
cv2.rectangle(frame, box, color, 2)
36+
cv2.putText(frame, label, (box[0], box[1] - 10),
37+
cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
38+
end_drawing = time.time()
39+
40+
fps_label = "FPS: %.2f (excluding drawing time of %.2fms)" % (
41+
1 / (end - start), (end_drawing - start_drawing) * 1000)
42+
cv2.putText(frame, fps_label, (0, 25),
43+
cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
44+
cv2.imshow("detections", frame)

0 commit comments

Comments
 (0)