1
00:00:02,000 --> 00:00:09,000
For now, we will see how we can do vehicle counting, entering and leaving using YOLO V8.

2
00:00:09,000 --> 00:00:14,000
So first of all, for this project I will be using this GitHub repo.

3
00:00:14,000 --> 00:00:17,000
So here are the steps provided to run the code.

4
00:00:17,000 --> 00:00:20,000
First I will run the code using the steps provided.

5
00:00:20,000 --> 00:00:25,000
Then I will explain you the complete code of the predict.py file.

6
00:00:25,000 --> 00:00:31,000
Okay, so when we run this script in this github repo we will be able to get the results.

7
00:00:31,000 --> 00:00:33,000
Like you can see over here.

8
00:00:33,000 --> 00:00:37,000
We will we will get the number of vehicles leaving the count of number of vehicles leaving.

9
00:00:37,000 --> 00:00:41,000
And we will also get the count of the number of vehicles entering.

10
00:00:41,000 --> 00:00:41,000
Okay.

11
00:00:41,000 --> 00:00:45,000
So here are the steps provided to run the code.

12
00:00:45,000 --> 00:00:47,000
So we will follow these steps and run the code.

13
00:00:47,000 --> 00:00:48,000
Now.

14
00:00:48,000 --> 00:00:51,000
So to run the code, I will open the PyCharm here.

15
00:00:51,000 --> 00:00:55,000
So here I will just write PyCharm and open PyCharm.

16
00:00:55,000 --> 00:00:57,000
So I will just follow step by step.

17
00:00:57,000 --> 00:01:02,000
So if you want to implement on your side, you can implement it on your site as well.

18
00:01:02,000 --> 00:01:07,000
So the repo I'm using is YOLO V8 Deepsort Object tracking by Mohammad Moin.

19
00:01:07,000 --> 00:01:13,000
It's my repo which I have created on one vessel YOLO v8 Deepsort object tracking.

20
00:01:13,000 --> 00:01:17,000
I will add the link in the description as well so you can check it from there as well.

21
00:01:17,000 --> 00:01:21,000
So I have opened PyCharm over here, so it's creating a workspace.

22
00:01:21,000 --> 00:01:24,000
Or you can say it's preparing the workspace currently.

23
00:01:25,000 --> 00:01:27,000
So it might take a few more seconds.

24
00:01:27,000 --> 00:01:29,000
Oh, so just close tip of the day.

25
00:01:30,000 --> 00:01:32,000
Don't need it currently, so we'll go to file.

26
00:01:34,000 --> 00:01:35,000
I click on new project.

27
00:01:37,000 --> 00:01:41,000
And from here I will choose the folder where I want to create the project.

28
00:01:41,000 --> 00:01:45,000
So I have created an empty folder by the name vehicle counting, entering and leaving.

29
00:01:45,000 --> 00:01:47,000
So this is this will.

30
00:01:48,000 --> 00:01:50,000
This will be my project main folder.

31
00:01:50,000 --> 00:01:55,000
So let's go from here and select this folder as my required folder.

32
00:01:55,000 --> 00:02:02,000
So just click over here, go to your course, and from here I will select vehicles counting, entering

33
00:02:02,000 --> 00:02:03,000
and leaving.

34
00:02:03,000 --> 00:02:09,000
Okay, So at please look at that location over here and location over here is same.

35
00:02:09,000 --> 00:02:10,000
Then click on create.

36
00:02:11,000 --> 00:02:14,000
So in this way I will create a new project over here.

37
00:02:14,000 --> 00:02:16,000
So this might take few seconds.

38
00:02:16,000 --> 00:02:17,000
Okay, so.

39
00:02:19,000 --> 00:02:24,000
We can see that the project is now created over here and the project file name is vehicles, count date

40
00:02:24,000 --> 00:02:26,000
and entering and leaving.

41
00:02:26,000 --> 00:02:31,000
Okay, So as this project is created, it's creating a virtual environment.

42
00:02:31,000 --> 00:02:32,000
Virtual environment.

43
00:02:32,000 --> 00:02:35,000
So, okay, so this project is created over here.

44
00:02:35,000 --> 00:02:40,000
So now I will just follow the steps in the repo and just do the implementation will open the terminal

45
00:02:40,000 --> 00:02:40,000
over here.

46
00:02:41,000 --> 00:02:43,000
Let's go to the repo over here.

47
00:02:44,000 --> 00:02:47,000
And just follow the steps provided in this post.

48
00:02:48,000 --> 00:02:48,000
Okay.

49
00:02:48,000 --> 00:02:51,000
So first of all, here are the steps to run the port.

50
00:02:51,000 --> 00:02:55,000
So first of all, I will go over here and clone the GitHub repo.

51
00:02:55,000 --> 00:03:01,000
So just click over here and copy this command and just paste it over here and click on Enter.

52
00:03:02,000 --> 00:03:04,000
Okay, so this might take a few seconds.

53
00:03:04,000 --> 00:03:06,000
It's currently cloning the GitHub repo.

54
00:03:06,000 --> 00:03:11,000
So after the GitHub repo is cloned, you can see the folder over here.

55
00:03:12,000 --> 00:03:12,000
Okay.

56
00:03:12,000 --> 00:03:15,000
So you can see that it's 67% done.

57
00:03:15,000 --> 00:03:20,000
But founder of my GitHub repo is created over here.

58
00:03:20,000 --> 00:03:25,000
And as this gets 100% so we can see the files over here as well.

59
00:03:25,000 --> 00:03:26,000
So.

60
00:03:28,000 --> 00:03:32,000
If we go over here, we counting, entering and leaving and just click over here.

61
00:03:32,000 --> 00:03:34,000
So now we will see all the files.

62
00:03:34,000 --> 00:03:38,000
So just wait a few seconds until it gets updated over here.

63
00:03:40,000 --> 00:03:45,000
Okay, so here we have vehicle counting, entering and leaving and.

64
00:03:49,000 --> 00:03:51,000
And here are the files.

65
00:03:51,000 --> 00:03:54,000
So here we have the ultralytics over here.

66
00:03:54,000 --> 00:03:56,000
This is the CoLab files are also there.

67
00:03:56,000 --> 00:04:00,000
So you can run this script or this project in the Google CoLab as well.

68
00:04:00,000 --> 00:04:09,000
So over here we also have the in Ultralytics if we go over here so we can also go inside YOLO, we ate

69
00:04:09,000 --> 00:04:14,000
and then we go to detect and we can also see the predict.py file over here as well.

70
00:04:14,000 --> 00:04:15,000
So.

71
00:04:16,000 --> 00:04:21,000
Let's set this project or this clone folder as our current directory.

72
00:04:21,000 --> 00:04:27,000
So to set this folder, our current directory, we will just copy this command and just paste it over

73
00:04:27,000 --> 00:04:27,000
here.

74
00:04:27,000 --> 00:04:33,000
So now this project is or this folder clone folder is set our current directory.

75
00:04:33,000 --> 00:04:34,000
So just click on Enter.

76
00:04:34,000 --> 00:04:37,000
So now this folder is being set.

77
00:04:37,000 --> 00:04:38,000
Our current directory.

78
00:04:38,000 --> 00:04:41,000
The folder name is YOLO Deepsort object tracking.

79
00:04:41,000 --> 00:04:47,000
So in the next step, what I will do is I will install all the dependencies or all the required libraries

80
00:04:47,000 --> 00:04:49,000
required to run this project.

81
00:04:49,000 --> 00:04:54,000
So if we skip this step, then in later on we might face this issue that the following library is not

82
00:04:54,000 --> 00:04:55,000
installed.

83
00:04:55,000 --> 00:04:59,000
For example, Hydra library is not installed or some other library is not installed.

84
00:04:59,000 --> 00:05:05,000
So it's always better to install all the required libraries by installing the dependencies.

85
00:05:05,000 --> 00:05:07,000
So just paste this command over here.

86
00:05:07,000 --> 00:05:12,000
So it will install all the dependencies and all the required libraries will also get installed.

87
00:05:13,000 --> 00:05:15,000
So this might take a few seconds.

88
00:05:15,000 --> 00:05:19,000
So if you are running the script for the first time, it will take time to install all the packages,

89
00:05:19,000 --> 00:05:23,000
but have been running this script quite a while, so it's appearing here.

90
00:05:23,000 --> 00:05:25,000
Requirements already satisfied.

91
00:05:26,000 --> 00:05:30,000
So now let's look at the another thing which so basically.

92
00:05:31,000 --> 00:05:37,000
Now we'll go to the detect folder as we are doing object detection and tracking in this project.

93
00:05:37,000 --> 00:05:41,000
So we will only focus on the tracking or detection and tracking.

94
00:05:41,000 --> 00:05:43,000
So we are not doing the segmentation.

95
00:05:43,000 --> 00:05:49,000
So now I will set this folder, detect folder as my current directory so I have the access to the predictor

96
00:05:49,000 --> 00:05:52,000
PI train dot pi and the validation dot pi script.

97
00:05:52,000 --> 00:05:55,000
So let me set this detect folder as my current directory.

98
00:05:55,000 --> 00:06:00,000
So now my current directory is being set to YOLO v8 detect folder.

99
00:06:01,000 --> 00:06:06,000
Now, in the next step, what I will do, I will go to the download and Deepsort files from the Google

100
00:06:06,000 --> 00:06:07,000
Drive by going towards this link.

101
00:06:07,000 --> 00:06:11,000
So just copy this link and just paste this link over here.

102
00:06:13,000 --> 00:06:18,000
Okay, so I will just download this deepsort python file by clicking on the right click, doing the

103
00:06:18,000 --> 00:06:20,000
right click and click on download.

104
00:06:20,000 --> 00:06:23,000
So it will download in the zip format.

105
00:06:23,000 --> 00:06:28,000
I will unzip it and just add it to this folder where I have this project.

106
00:06:28,000 --> 00:06:32,000
So it's zipping currently the folder, so it might take few seconds.

107
00:06:38,000 --> 00:06:39,000
But it will not take very much time.

108
00:06:39,000 --> 00:06:40,000
So.

109
00:06:40,000 --> 00:06:42,000
Okay, so now the file is zipped.

110
00:06:42,000 --> 00:06:43,000
Now it will start downloading.

111
00:06:45,000 --> 00:06:47,000
It will take around eight seconds further.

112
00:06:47,000 --> 00:06:48,000
Okay.

113
00:06:48,000 --> 00:06:50,000
So it's very soon it will be done from here.

114
00:06:50,000 --> 00:06:52,000
So as it completes.

115
00:06:52,000 --> 00:06:58,000
Okay, so the file has been downloaded, but it's a zip file, so we will just go over here.

116
00:06:58,000 --> 00:06:59,000
Okay.

117
00:06:59,000 --> 00:07:00,000
But okay, we can see now.

118
00:07:01,000 --> 00:07:08,000
Okay, just copy this from here and just go to your V8 and your V8 course over here and let's see what's

119
00:07:08,000 --> 00:07:11,000
the name of vehicle counting, entering and leaving?

120
00:07:11,000 --> 00:07:12,000
What's the name of our project?

121
00:07:13,000 --> 00:07:14,000
As far as I remember.

122
00:07:14,000 --> 00:07:18,000
Okay, so let's go towards our project because counting, entering and leaving.

123
00:07:18,000 --> 00:07:18,000
Okay.

124
00:07:18,000 --> 00:07:20,000
Just open the wrong file.

125
00:07:20,000 --> 00:07:22,000
Okay, so now I will go over here.

126
00:07:22,000 --> 00:07:22,000
Okay?

127
00:07:22,000 --> 00:07:23,000
Just.

128
00:07:23,000 --> 00:07:27,000
Just click over here and just place this folder over here.

129
00:07:27,000 --> 00:07:30,000
I don't need this, so just close it currently.

130
00:07:30,000 --> 00:07:31,000
Okay?

131
00:07:31,000 --> 00:07:35,000
So just extract the files from here and click on.

132
00:07:35,000 --> 00:07:36,000
Okay.

133
00:07:36,000 --> 00:07:37,000
Okay.

134
00:07:37,000 --> 00:07:39,000
So all the files will be extracted.

135
00:07:39,000 --> 00:07:42,000
Then go over here and just copy this folder from here.

136
00:07:42,000 --> 00:07:52,000
Then go back and click on your Deepsort Object Tracking YOLO Ultralytics YOLO V8 Detect and just paste

137
00:07:52,000 --> 00:07:53,000
this folder over here.

138
00:07:53,000 --> 00:07:54,000
So that's cool.

139
00:07:55,000 --> 00:07:57,000
So in the next step, what I will do is I.

140
00:07:58,000 --> 00:08:00,000
I have the deepsort pytorch object.

141
00:08:00,000 --> 00:08:06,000
Because what we are why we are downloading deepsort pytorch folder because we are implementing object

142
00:08:06,000 --> 00:08:07,000
tracking using deepsort.

143
00:08:07,000 --> 00:08:11,000
So we need to have the deepsort files in our required directory as well.

144
00:08:11,000 --> 00:08:15,000
Okay, so what's next is I don't need this now.

145
00:08:15,000 --> 00:08:15,000
Okay.

146
00:08:15,000 --> 00:08:18,000
So now let's download a sample video from Google Drive.

147
00:08:18,000 --> 00:08:21,000
So I have this this folder into detect folder.

148
00:08:21,000 --> 00:08:23,000
So I'm right by this way.

149
00:08:23,000 --> 00:08:28,000
So just go over here and just download a demo video for testing from the Google Drive.

150
00:08:28,000 --> 00:08:33,000
So I'm just downloading a demo video for the testing from the Google Drive.

151
00:08:34,000 --> 00:08:36,000
So this might take a few more seconds.

152
00:08:36,000 --> 00:08:37,000
So it's 100%.

153
00:08:37,000 --> 00:08:40,000
So the demo video is being downloaded from that Google Drive.

154
00:08:40,000 --> 00:08:42,000
Now we'll run this script.

155
00:08:42,000 --> 00:08:46,000
So basically we are performing object tracking detection, tracking plus vehicle counting.

156
00:08:46,000 --> 00:08:49,000
So we need to download the files from here.

157
00:08:49,000 --> 00:08:53,000
So I will just go over here and download the update predict.py file.

158
00:08:54,000 --> 00:08:59,000
Okay, so just download this file from here and just click on right click.

159
00:09:01,000 --> 00:09:03,000
And I think the processing is becoming slow.

160
00:09:03,000 --> 00:09:07,000
I don't know what the reason, but let's just do a right click.

161
00:09:07,000 --> 00:09:09,000
I think it might take some time.

162
00:09:09,000 --> 00:09:16,000
Okay, so just click on here, download, okay, download anyway, and just go back over here and the

163
00:09:16,000 --> 00:09:18,000
file is downloaded over here, so that's cool.

164
00:09:18,000 --> 00:09:26,000
Okay, so here is our file showing folder and just copy it and just go over to the detect folder and

165
00:09:26,000 --> 00:09:33,000
just place this over here and just remove this predict.py file and just I'm just remove the previous

166
00:09:33,000 --> 00:09:34,000
predict.py file.

167
00:09:35,000 --> 00:09:36,000
Please check this.

168
00:09:36,000 --> 00:09:37,000
Okay.

169
00:09:37,000 --> 00:09:39,000
So I am doing, I think I'm doing a correct way.

170
00:09:41,000 --> 00:09:47,000
Now I will run this script by clicking on predict.py file and just pasting this command over here and

171
00:09:47,000 --> 00:09:48,000
just clicking on enter.

172
00:09:48,000 --> 00:09:50,000
So now the script will run.

173
00:09:50,000 --> 00:09:55,000
As the script starts to run, I will explain you the complete code and the process as well.

174
00:09:56,000 --> 00:09:57,000
Okay.

175
00:09:57,000 --> 00:09:57,000
So.

176
00:09:59,000 --> 00:10:05,000
The script has started to execute, so this might take few seconds to start, but as the processing

177
00:10:05,000 --> 00:10:09,000
starts on the video, so we will explain you the step by.

178
00:10:09,000 --> 00:10:14,000
I will explain you the code step by step so it comes easy for you to understand.

179
00:10:15,000 --> 00:10:17,000
Okay, so the weights are loaded.

180
00:10:17,000 --> 00:10:18,000
Okay?

181
00:10:18,000 --> 00:10:21,000
So just don't ask me again, please.

182
00:10:22,000 --> 00:10:25,000
Okay, so now the weights are being downloaded.

183
00:10:25,000 --> 00:10:26,000
Your the V8 empty.

184
00:10:26,000 --> 00:10:31,000
So we are using your V8 pre-trained model for this project.

185
00:10:31,000 --> 00:10:38,000
YOLO V8 comes with six different models YOLO V8 and is the smallest, but it is the fastest as well.

186
00:10:38,000 --> 00:10:39,000
But it compromises on accuracy.

187
00:10:39,000 --> 00:10:44,000
YOLO V8 is the most accurate, but it is less in speed.

188
00:10:44,000 --> 00:10:49,000
Or you can say it is not as fast as compared to the other YOLO V8 model.

189
00:10:49,000 --> 00:10:57,000
So the script has started to run and if I click over here to see the live demo, what I'm getting over

190
00:10:57,000 --> 00:10:57,000
here.

191
00:10:57,000 --> 00:11:05,000
So okay, so just see one of the results and then we can will go to words to explain you the complete

192
00:11:05,000 --> 00:11:05,000
code.

193
00:11:07,000 --> 00:11:11,000
And we'll be just focusing on seeing one of the results only and will explain you the complete code.

194
00:11:11,000 --> 00:11:14,000
So after seeing only one of the results.

195
00:11:14,000 --> 00:11:18,000
So okay, so as you can see over here.

196
00:11:19,000 --> 00:11:22,000
Let me see what results over here.

197
00:11:22,000 --> 00:11:25,000
So as this trails crosses this line.

198
00:11:28,000 --> 00:11:29,000
Okay.

199
00:11:30,000 --> 00:11:32,000
So let's see what we get over here.

200
00:11:32,000 --> 00:11:36,000
So by just I'm seeing as this train crosses this line.

201
00:11:36,000 --> 00:11:41,000
So basically, when this train, you can see that this trail is moving the south north direction, basically

202
00:11:41,000 --> 00:11:43,000
this direction is the north direction.

203
00:11:43,000 --> 00:11:49,000
So as this train is intersect with this line, please focus on, you will see the number of vehicles

204
00:11:49,000 --> 00:11:49,000
entering.

205
00:11:49,000 --> 00:11:53,000
So as this train, the color of this line, green line will also change.

206
00:11:53,000 --> 00:11:53,000
Okay.

207
00:11:53,000 --> 00:11:54,000
Change to white.

208
00:11:54,000 --> 00:11:58,000
And the number of vehicle entering is now truck is equal to one, although it's directing it wrongly.

209
00:11:58,000 --> 00:12:05,000
But if you use a yellow x or yellow eight larger model or medium model, then it will give the fine

210
00:12:05,000 --> 00:12:05,000
results.

211
00:12:05,000 --> 00:12:12,000
I'm using YOLO v eight but on the larger model it gives that it good accurate detections.

212
00:12:12,000 --> 00:12:17,000
Okay, so now when this train is coming from here, these trails intersect with this line.

213
00:12:17,000 --> 00:12:20,000
You will see the increment over here, the number of vehicles leaving.

214
00:12:20,000 --> 00:12:22,000
So let's see over here.

215
00:12:25,000 --> 00:12:27,000
Okay, So let's see.

216
00:12:27,000 --> 00:12:29,000
Just it will take a few more minutes.

217
00:12:29,000 --> 00:12:35,000
Okay, So I'm just waiting for these trails to cross this line so you can see these trails, these lines

218
00:12:35,000 --> 00:12:36,000
below.

219
00:12:36,000 --> 00:12:42,000
So when this line trail intersect with this green line, you will see an increment of the number of

220
00:12:42,000 --> 00:12:44,000
vehicles leaving.

221
00:12:44,000 --> 00:12:44,000
Okay.

222
00:12:44,000 --> 00:12:49,000
So as we are implementing object tracking over here as well using Deepsort, So what object tracking

223
00:12:49,000 --> 00:12:52,000
is, is basically an object tracking.

224
00:12:52,000 --> 00:12:57,000
We assign a unique ID to each of the detected object like you can see over here.

225
00:12:57,000 --> 00:12:58,000
Here we have detected the car.

226
00:12:58,000 --> 00:13:02,000
Here you can see a unique ID by the number four with this object here.

227
00:13:02,000 --> 00:13:05,000
We also detected a car and you can see a unique ID 15.

228
00:13:05,000 --> 00:13:10,000
And here we also have detected the car and you can see unique added 12 here.

229
00:13:10,000 --> 00:13:14,000
We have also detected the car and you can see a unique ID 11.

230
00:13:14,000 --> 00:13:17,000
So these unique IDs are being assigned randomly.

231
00:13:17,000 --> 00:13:22,000
It is not in the incremental order, like you can say after one, two, three, four, basically model

232
00:13:22,000 --> 00:13:24,000
assign these unique IDs randomly.

233
00:13:24,000 --> 00:13:30,000
Like after four, there can be ten, there can be 15, there can be 105, there can be 200.

234
00:13:30,000 --> 00:13:33,000
So these unique IDs are being assigned randomly.

235
00:13:33,000 --> 00:13:33,000
Okay.

236
00:13:33,000 --> 00:13:38,000
Like for 15, 12, seven, 11, and here I can see that two as well.

237
00:13:38,000 --> 00:13:39,000
And here it is.

238
00:13:39,000 --> 00:13:46,000
Eight So these unique IDs are being assigned randomly, so you don't need to worry like, well, I'm

239
00:13:46,000 --> 00:13:47,000
not getting in the order.

240
00:13:47,000 --> 00:13:52,000
So these IDs are being assigned randomly, so you don't need to worry at all.

241
00:13:54,000 --> 00:13:59,000
So now in the next step, we will see that if as this train like you can see this train, please focus

242
00:13:59,000 --> 00:14:05,000
on what my mouth says as this train like you can see this point, center point, this center point,

243
00:14:05,000 --> 00:14:07,000
the bottom coordinate.

244
00:14:07,000 --> 00:14:13,000
So this is our boat at the bottom of the bounding box, the center point at the bottom of the bounding

245
00:14:13,000 --> 00:14:14,000
box.

246
00:14:14,000 --> 00:14:14,000
Okay.

247
00:14:14,000 --> 00:14:20,000
So when this train intersect with this line, you will see an increment in the count of the number of

248
00:14:20,000 --> 00:14:21,000
vehicles leaving.

249
00:14:21,000 --> 00:14:21,000
Okay.

250
00:14:21,000 --> 00:14:23,000
So just focus on this line.

251
00:14:23,000 --> 00:14:28,000
And as this trail intersect with this line, you can say that this trail is intersecting with this line

252
00:14:28,000 --> 00:14:31,000
and you can see that the car is detected.

253
00:14:31,000 --> 00:14:37,000
And when this trail intersect with this line, you will see that the this trail, this trail intersect

254
00:14:37,000 --> 00:14:39,000
with this line, this green line.

255
00:14:39,000 --> 00:14:43,000
You can see that the number of vehicles entering as the car as one.

256
00:14:43,000 --> 00:14:43,000
Okay.

257
00:14:45,000 --> 00:14:48,000
So just focus on this result.

258
00:14:48,000 --> 00:14:51,000
Only then I will explain you the predict dot pie script.

259
00:14:51,000 --> 00:14:53,000
What's in it?

260
00:14:53,000 --> 00:14:55,000
Okay, so just.

261
00:14:55,000 --> 00:14:58,000
I'm waiting for this to intersect.

262
00:14:58,000 --> 00:14:58,000
Okay.

263
00:14:58,000 --> 00:15:02,000
So as this train intersect with this line, you can see that we have the increment.

264
00:15:02,000 --> 00:15:03,000
The car is equal to one.

265
00:15:03,000 --> 00:15:06,000
So let's move towards the code and I will explain you the code now.

