WEBVTT

00:00.080 --> 00:08.680
We downloaded the data set into the folder Object Detection Android, and we imported it into our notebook.

00:08.920 --> 00:12.400
Now we're going to train the model.

00:12.440 --> 00:18.960
At first we need to edit this file called data dot YAML or y.

00:20.320 --> 00:26.360
Okay here we have the names only one class which is the battery.

00:26.720 --> 00:28.280
It's from Roboflow.

00:28.440 --> 00:35.320
And here we need to edit the test train and val variables.

00:35.360 --> 00:43.440
Let me get the test images copy path and here change the test to this.

00:43.640 --> 00:45.520
Also go to the train.

00:45.520 --> 00:51.920
Copy the Path of images folder from the train folder and paste it here.

00:52.040 --> 00:58.840
Also for the valid copy the images, copy path and paste it like this.

00:58.960 --> 01:02.250
Click save and close the file.

01:02.250 --> 01:06.210
So we added it this data dot YAML for a file.

01:06.250 --> 01:09.570
Now we're going to train our model.

01:09.850 --> 01:10.330
Okay.

01:10.530 --> 01:20.650
So our um our uh content folder contains only one file folder sorry which is object detection.

01:20.650 --> 01:21.370
Android.

01:21.410 --> 01:21.890
Okay.

01:22.210 --> 01:23.690
Uh, forget the sample data.

01:23.730 --> 01:27.210
This is a ready made one for every project.

01:27.490 --> 01:31.490
Uh, we created this object detection android.

01:31.530 --> 01:34.730
Okay, now let's train our model.

01:34.810 --> 01:43.130
At first, we need to install the ultra Lytics in order to use one of those, uh, one of those, um,

01:43.410 --> 01:44.930
YOLO versions.

01:44.930 --> 01:47.530
And we're going to use, uh, s or N.

01:47.690 --> 01:49.650
This is best for Android.

01:49.810 --> 01:55.810
So pip install ultra lytics click run and here we go.

01:56.130 --> 01:57.330
We execute it.

01:57.370 --> 01:58.970
Now scroll down.

01:59.010 --> 02:06.310
Create a new code cell and from ultra lytics import flow.

02:06.350 --> 02:10.070
Here, let me make this annotation.

02:10.190 --> 02:20.950
Load a model YOLO version eight not YAML, it's PT, so make sure you copy it if we go and open YOLO

02:20.950 --> 02:27.190
version YOLO 11 and it's YOLO 11 and PT okay.

02:27.350 --> 02:36.270
Also there are uh, the there are a lot of versions you can see in the page of ultra Lytics.

02:36.430 --> 02:44.310
So, uh, it's the best and the most used one is YOLO version eight.

02:44.350 --> 02:44.830
Okay.

02:45.150 --> 02:52.710
So there are a lot of versions we're gonna use YOLO version eight, which is a better and well-tested.

02:52.710 --> 02:57.550
So YOLO version eight and which is nano.pt.

02:57.910 --> 03:01.280
PT is the model extension.

03:01.280 --> 03:03.400
Now let's use this model.

03:03.640 --> 03:08.080
Results equals to model dot train.

03:08.120 --> 03:15.200
Now that train that train function needs a trainer and arguments.

03:15.440 --> 03:23.200
So here we need to pass the data equals to the content data YAML.

03:23.200 --> 03:24.440
So copy this.

03:24.680 --> 03:31.320
Copy the path of this file because it's very important from our object detection Android as.

03:31.320 --> 03:41.640
And as I told you we need to edit this file to correctly pass the images of validation images of training

03:41.640 --> 03:43.480
and images of testing.

03:43.480 --> 03:46.880
So make sure you edit this file before using it.

03:47.080 --> 03:50.320
Otherwise many problems will occur.

03:50.360 --> 04:00.780
Okay, so copy the path of it and paste it and pass it as the data of that data have the data parameter

04:00.780 --> 04:03.020
here of this train function.

04:03.060 --> 04:03.580
Okay.

04:03.780 --> 04:07.060
How many, uh, epochs we need?

04:07.100 --> 04:09.700
We need to, well, train our model.

04:09.700 --> 04:13.540
So I'm going to use the apex uh, 100.

04:13.820 --> 04:15.940
Also the image size.

04:15.940 --> 04:19.380
As I told you, we use 600 by 40.

04:19.420 --> 04:30.220
If we go to this table, the size will result will be, uh, will be in 640 times 640 height times width.

04:30.380 --> 04:30.860
Okay.

04:31.020 --> 04:38.580
And use the device I'm going to use, uh, if you have the GPU, you can select it one.

04:38.580 --> 04:41.460
Otherwise we're going to use the CPU.

04:41.700 --> 04:43.140
So device equals to zero.

04:43.140 --> 04:52.380
Also you can change the runtime uh to use a TPU, TPU and T4 GPU or you can use the CPU.

04:52.580 --> 04:57.950
It's not a big deal if you have a big data set, always use the GPU.

04:58.190 --> 04:59.470
Okay, run.

04:59.470 --> 05:04.590
This is, uh, this is resulting from, uh, changing the runtime.

05:04.590 --> 05:13.430
So if you change the runtime, just click run all to, to run all the previous codes and then execute

05:13.430 --> 05:13.950
this.

05:13.990 --> 05:14.470
Okay.

05:14.750 --> 05:21.990
So when changing the runtime, all the previous codes will be uh, will be removed or resetted.

05:22.030 --> 05:25.590
Um, and you should execute them again.

05:25.590 --> 05:26.030
Okay.

05:26.070 --> 05:30.070
So this is the first one now in training the data set.

05:30.070 --> 05:32.790
And here let's try to remove the device.

05:33.070 --> 05:37.310
If you have uh just the CPU run again.

05:37.310 --> 05:38.230
And here we go.

05:38.430 --> 05:45.630
So I removed the device because I'm not using the GPU of uh, the, the Google notebook.

05:45.870 --> 05:51.790
And please, guys, don't exit because we are executing here.

05:51.990 --> 05:54.150
So this is the first epic.

05:54.150 --> 05:55.950
It will be created here.

05:56.070 --> 06:00.000
And you see guys starting training for 100 epochs.

06:00.000 --> 06:07.480
Lugging results will be created to the content runs detect train and this is the first epoch.

06:07.760 --> 06:12.040
The image size is this and wait for the epochs.

06:12.200 --> 06:22.280
Also there is a very important note here that if you uh, if you notice that the training is slow because

06:22.280 --> 06:28.880
we are using the CPU, if you change it to GPU, it's faster.

06:29.080 --> 06:30.960
So let me change it to this.

06:30.960 --> 06:34.160
Click D for GPU, click save.

06:34.400 --> 06:37.760
Now we need to restart the runtime.

06:37.800 --> 06:38.280
Okay.

06:38.520 --> 06:41.720
Again let me click run all.

06:41.880 --> 06:46.240
And here it's very simple to use the GPU.

06:46.280 --> 06:50.920
Using the device equals to zero using the GPU.

06:51.160 --> 06:57.940
So I want from you to understand that using GPU is faster and in order to use the GPU.

06:58.260 --> 07:00.780
Use the change runtime.

07:01.060 --> 07:02.220
Default GPU.

07:02.220 --> 07:06.180
And to use this GPU you should use devices.

07:06.540 --> 07:09.940
Device equals to zero parameter when training the model.

07:09.940 --> 07:17.180
And if you notice guys that it's very, very and much faster than before, we are training the model

07:17.180 --> 07:19.780
in a fastest way using the GPU.

07:20.020 --> 07:22.180
And congratulations guys.

07:22.180 --> 07:27.220
100 epochs completed in 0.03 hours.

07:27.220 --> 07:31.020
And the validation is here the Ultralytic.

07:31.220 --> 07:36.740
And you see guys we have the results saved to content.

07:36.740 --> 07:38.940
The content is this folder right.

07:39.020 --> 07:39.540
Ones.

07:39.900 --> 07:45.380
This is the newly created folder runs Detect and Train.

07:45.620 --> 07:49.300
So here is our model.

07:49.300 --> 07:51.340
And the results is here.
