Hi, guys.
Welcome back to the course.
This is going to be our first object detection lesson.
So let's get started.
So the first model we're going to trend this object detector is a skilled YOLO v4, and this one is
a very cool one.
I started with a pretty cool project, in my opinion.
This one is a gun and pistol detection detector.
So let's take a look.
So open up Notebook 42, which is highlighted here, and that'll bring up this window.
So this is a lesson here.
So firstly, like I mean, I've mentioned before all of these notebooks adopted from rebel floor, they
may not be the latest notebooks that are available right now in rubber floor site because they're constantly
tweaking and making little changes to these notebooks.
So what I did this was back in 2021, believe November.
I captured those notebooks and I may have made some minor changes because some of those things, some
of their notebooks are broken.
Unfortunately, they do get around to fixing it quite quick.
So if you do encounter one of the newer ones that are broken, you can just send them a message and
they'll probably update it quite quickly.
So this one here is a skilled healer before, and it's going to be trained on the Pistol Pistols dataset.
As you can see here, this is an example of how the dataset looks, and we have pictures of guns where
we have the bounding boxes annotated around it.
This is our training data.
This is what we'll use to create our very own gun and pistol detector.
So you can see how all of these things, these the guns here in this footage just as a robbery.
Most of these look like studio or movie shots or stock images.
Nevertheless, that's still useful because they all have guns in them, and you're not going to encounter
a real life gun dataset unless someone put in the works to build one.
It's possible.
It's a lot of footage on YouTube of like CCTV robberies, especially in the US, where there is no gun
control.
That's not a political opinion.
That's just a fact.
So let's start this notebook.
So one of them, the first is not books.
They they're a bit heavy.
There's a lot of setup going on because using your look for you'll five all of these abductors.
They're not actually meant to be run in notebooks because they got a lot of things going on in the background.
A lot of parts that need to be build a lot of different configurations, so it looks a bit messy when
it's in a notebook.
But nevertheless, this is perhaps the easiest way to get started with this object detector notebooks.
So I'm not going to run this code here because right now I've run these before.
I will just say this takes these few blocks cells out of code.
Some of them do take maybe a couple minutes to run.
Shouldn't be that long.
The longest one might be this one, I believe.
But you can see this is the output here.
This is what you should be seeing.
We have to install PI.
No.
Then we get to navigate to the directory.
Then we have to download the data set.
So we have the instructions here.
So the format we're going to be using is the YOLO v five PI torch export format, which I've already
done here.
This is the well, this is the this part doesn't really work actually anymore.
Let's just to live this.
So I've actually uploaded the dataset to Google Drive in some cases in a sets of go down from river
forward to change the format of their hosting.
So we get the unzip sort of the pistols here and we unzip it.
Then we just set up the windmill file and then we just inspect the architecture by doing cat to.
This is displaced the architecture of the yellow freeform scaled model.
You can see it's here.
You can see the backbone of the anchors.
This is a number of classes that we're retraining on here.
Well.
That's what it was pre-trained on that.
Actually, we're going to be training on one class in a way that students dataset.
And this is the head of Uber.
For her, this is a useful tool in the CSP darknet backbone, I believe.
And now here's where we train the other model, so you can see if we can pass a number of these input
arguments here using the OK path style.
So you can see we run the Python file like this, but exclamation so that we can run a Python file.
Time actually just times it's performance.
Pretty useful metric to look at when you're training models.
So we set the image size, how many batches of images we're going to use per batch.
So sixteen number of epochs.
Then we set the directory of the Y.A. data file.
Then we set the model, the sort of the model configuration.
Then we said to which we're not going to use between weights, we're training from scratch.
And then we just put two results here, and cash means that we're going to put the data in your.
So this is a GPO will be recruiting it on.
And now here we go.
So it's training, so you can see it takes quite some time.
I've been training this for maybe 15, 20 minutes now and you can see it's already reached at AT&T Park
and that is with using the GPU and club.
And I have a cooler approach which may give me slightly faster GPU compared to what you might be using,
although I can't say for sure.
So you can see it's taking roughly a minute to beatbox.
Not that bad.
So this is what you can expect after you finish training so you can actually launch a tensor board.
And measures to its training performance is quite useful to use if you want to make it persistent so
that you will receive the results.
I would encourage you to use something like weights and biases, which is a really good library and
tool to keep storing your training results.
It works seamlessly when you'll have five for multiple attacks.
So I would encourage you to use that.
This because this tensor mode is not going to remain after we exit the notebook.
I mean, it will be there, but the actual explicit results wouldn't be there.
And then it'll be difficult for you to compare experiments when you have two different runs.
Yeah.
So you can see this is another metric.
This is from the actually all four results directory.
You can look at the IOU, the object in this, which I'm not even sure what that is.
You can look at precision and recall always good.
The map scores are very good to look at as well, because these take into consideration bounding boxes
and classification scores.
Precision and recall again, she didn't mention, but they're always very useful to look at.
So the four boxes on the right here are perhaps the most useful metrics to look at when treating these
models.
And I agree, because you can directly compare map, especially these to map scores with other models
as well, because they tend to all use maps two point five and a map of the range point five two point
ninety five as well.
So let's take a look at this.
All right, let's visualize some of our training data here.
So this is the 22 we saw previously.
No.
Let's take a look at some of the actual results from our train from training on model.
You can see it doesn't have a class theme like gun, a pistol.
It just has class zero, which is OK.
You can always rename those things later on and you can see it's getting the gun in almost every photo
here.
This is actually quite good.
I'm actually quite impressed with this performance.
It definitely has learnt the shape of a gun in all of these photos, and the bombing boxes are quite
good as well.
However, actually, this isn't the only one here.
It didn't get these two rifles here.
That's a bit surprising.
Maybe doesn't have enough training data, or maybe it's just trained on pistols and not rifles.
I actually haven't checked.
I believe it missed part of this gun here because this is a cropped image right now, and you can see
it doesn't get the gun here, but that's still not too bad.
So if he wants to run an inference windows string widths, these are the words that we've trained so
far.
You can see it's towards the words after every epoch here, and this basically is probably the last
we had to.
And this is a one who probably want to use the best wits and you can see just the drunk rendered early
detection.
All you have to do is store some images in a test over here.
Set these parameters.
This is a confidence threshold.
If you want to lose your confidence threshold like point one, you're probably going to get a lot of
false positives.
However, you set it too high at twenty seven point six, you're going to miss a lot of guns and hence
have a bad recoil.
So let's give and take point four.
I would say 0.3 to point six is usually a good value to use.
More often than not, I tend to use lower confidence thresholds because it depends on the application.
But sometimes you just want to try to get as much of the detectors going, and you don't care too much
about false positives.
But that really does depend on your application.
And you can see we are loading the best model with its here and we're running detect so detected as
a python file in the area of reform model that runs detections on these images here.
So we can see it runs on all of these images in test folder.
Here you can see it's quite a bit of a tiff that runs pretty quick, to be honest.
When zero, two or three seconds, that's almost real time, in my opinion.
Almost 20 frames a second believe actually, it would be.
And then you can see you can display some of the outputs here, so you can take a look at some of the
images here.
You can see it auto getting the guns correctly, which is quite good.
The French are going to sequence pictures that don't look too difficult.
Maybe there will be some more difficult ones lower down, hopefully because it will look a bit repetitive
here.
But nevertheless, we are getting the guns down great.
So that concludes this lesson on the yellow v4 skilled object detector trained on the guns and arms
data sets if you wanted to export your words to download.
You can just run this line here as well.
Always good to keep track.
Keep track of your training day to hear your training progress, I should say so you can see what's
going on to know if it's 17 epochs and things to look for.
You can see the scores different metrics here.
My point, Dave, my point five point nine five point five Precision Recall targets, classes.
All this good stuff here.
All the metrics actually are quite here right now, and you can measure it so you can just take a look
and see if these metrics are getting better all the time.
And you can see you can look at the Map Point five score.
You can see it's two point fifty five now.
And initially we started at point where it's a point five zero two, I guess.
Yeah, it looks like it could be boxier.
So that's it for this lesson.
I hope you enjoyed it.
In the next lesson, we'll take a look at mass detection using TensorFlow Object Detection Library.
So my selection meeting the Alison King machines initially in my head but is actually to mass like those
face masks to wear because of the pandemic.
Well, we're going to do a mass detector next, so stay tuned for that.
Thank you.