We downloaded the data set into the folder Object Detection Android, and we imported it into our notebook.
Now we're going to train the model.
At first we need to edit this file called data dot YAML or y.
Okay here we have the names only one class which is the battery.
It's from Roboflow.
And here we need to edit the test train and val variables.
Let me get the test images copy path and here change the test to this.
Also go to the train.
Copy the Path of images folder from the train folder and paste it here.
Also for the valid copy the images, copy path and paste it like this.
Click save and close the file.
So we added it this data dot YAML for a file.
Now we're going to train our model.
Okay.
So our um our uh content folder contains only one file folder sorry which is object detection.
Android.
Okay.
Uh, forget the sample data.
This is a ready made one for every project.
Uh, we created this object detection android.
Okay, now let's train our model.
At first, we need to install the ultra Lytics in order to use one of those, uh, one of those, um,
YOLO versions.
And we're going to use, uh, s or N.
This is best for Android.
So pip install ultra lytics click run and here we go.
We execute it.
Now scroll down.
Create a new code cell and from ultra lytics import flow.
Here, let me make this annotation.
Load a model YOLO version eight not YAML, it's PT, so make sure you copy it if we go and open YOLO
version YOLO 11 and it's YOLO 11 and PT okay.
Also there are uh, the there are a lot of versions you can see in the page of ultra Lytics.
So, uh, it's the best and the most used one is YOLO version eight.
Okay.
So there are a lot of versions we're gonna use YOLO version eight, which is a better and well-tested.
So YOLO version eight and which is nano.pt.
PT is the model extension.
Now let's use this model.
Results equals to model dot train.
Now that train that train function needs a trainer and arguments.
So here we need to pass the data equals to the content data YAML.
So copy this.
Copy the path of this file because it's very important from our object detection Android as.
And as I told you we need to edit this file to correctly pass the images of validation images of training
and images of testing.
So make sure you edit this file before using it.
Otherwise many problems will occur.
Okay, so copy the path of it and paste it and pass it as the data of that data have the data parameter
here of this train function.
Okay.
How many, uh, epochs we need?
We need to, well, train our model.
So I'm going to use the apex uh, 100.
Also the image size.
As I told you, we use 600 by 40.
If we go to this table, the size will result will be, uh, will be in 640 times 640 height times width.
Okay.
And use the device I'm going to use, uh, if you have the GPU, you can select it one.
Otherwise we're going to use the CPU.
So device equals to zero.
Also you can change the runtime uh to use a TPU, TPU and T4 GPU or you can use the CPU.
It's not a big deal if you have a big data set, always use the GPU.
Okay, run.
This is, uh, this is resulting from, uh, changing the runtime.
So if you change the runtime, just click run all to, to run all the previous codes and then execute
this.
Okay.
So when changing the runtime, all the previous codes will be uh, will be removed or resetted.
Um, and you should execute them again.
Okay.
So this is the first one now in training the data set.
And here let's try to remove the device.
If you have uh just the CPU run again.
And here we go.
So I removed the device because I'm not using the GPU of uh, the, the Google notebook.
And please, guys, don't exit because we are executing here.
So this is the first epic.
It will be created here.
And you see guys starting training for 100 epochs.
Lugging results will be created to the content runs detect train and this is the first epoch.
The image size is this and wait for the epochs.
Also there is a very important note here that if you uh, if you notice that the training is slow because
we are using the CPU, if you change it to GPU, it's faster.
So let me change it to this.
Click D for GPU, click save.
Now we need to restart the runtime.
Okay.
Again let me click run all.
And here it's very simple to use the GPU.
Using the device equals to zero using the GPU.
So I want from you to understand that using GPU is faster and in order to use the GPU.
Use the change runtime.
Default GPU.
And to use this GPU you should use devices.
Device equals to zero parameter when training the model.
And if you notice guys that it's very, very and much faster than before, we are training the model
in a fastest way using the GPU.
And congratulations guys.
100 epochs completed in 0.03 hours.
And the validation is here the Ultralytic.
And you see guys we have the results saved to content.
The content is this folder right.
Ones.
This is the newly created folder runs Detect and Train.
So here is our model.
And the results is here.