Welcome back in this section, we'll take a look at how we can use CNN as a feature extractor increase.
So let's open this notebook here.
I believe this thing is still going on to keep you from the previous lesson, so let's stop this and
close it.
So now we have our feature extraction that books, you know, that make don't make the same mistake,
let's make this short for you.
And it is.
So let's take a look at what we're going to do here.
So in this dataset, we're going to use a Big 16 to extract features from our base dataset, and that's
going to be our dogs in this cats dataset.
Not the same one.
We took them from the Keros TensorFlow sorry to TensorFlow datasets package that we used in the previous
lesson that we're going to use our own Catzavelos dogs that said that we download.
And then we just set this up here.
This is we put everything into a pandas data frame.
The graph, should you before and now what we do, that's load our big network with all the top.
So we get our network there.
This will finish.
This will run when this dataset has been finished, downloading it on something and it is now.
So yep, it's going to run.
It's going to download a Big 16 image net, which which doesn't take too long and we're ready to go.
So now we can take a look at the model summary here you can see we have 14 million parameters right
now, so it's a fairly big network, as you can see.
So let's see what else we're going to do now.
So just fix this diagram in the code because the link was broken before.
So let's go back to this.
What are we doing here?
Well, we're using the 5G network as a feature extractor, so ignoring this densely ahead is green nodes
here.
We're just passing all of the images into this network here and extracting this seven by seven by 512.
That's the outputs from this node we're going to be extracting.
That would basically imagine this seven by seven by five 12 isn't, including from the full image of
four images by the CNN.
That's exactly what it is.
So we're doing this running this loop here that basically runs through all of the batches here and extracts
the features and stores that in this image, which is very hip.
That's all that we're doing here.
We're just taking images, setting them up so we can pre-purchase them to the network using the image
that utility is to pre process and passing it to the model predicts.
Remember which model is just a convolutional model?
It has not fully connected layers at the top, and that's it.
So this takes a while to run.
So I'm leaving it here to run, but I run to the lesson as well.
So you can see the rest of the output, so the image features that we get.
Remember, there are going to be a seven by seven where it is a tier, seven by seven by five 12.
It's quite a large number, but that's what we're going to be using as the input to our new classifier.
So this is what it looks like has quite a few big.
You can see it actually right now.
This is a batch right here to the to by 250000.
Actually, that's 25000 sorry, idiots.
So that's what that this number means.
So you can see we have this batch of 32 images and these are the encoding for them.
And you can see the image labels what they look like cats, first dogs for each batch.
That's why there's this array of 32 here.
So now what we're going to do, we're going to train a logistic regression classifier on those features.
So we use a list comprehension here just to get the image levels, detailed image features data and
then we can visit.
This should be can fit to Nampai areas here.
So then we can now use this as an input into the logistic regression classifier.
So we just use train to splitter because remember, a dataset was just all those images we set up from
before those training images.
So we just split it into 80 percent, 20 percent, which is set up a logistic regression here using
the logistic regression object here, said C Equal 2.1.
That's one of the parameters for logistic regression.
And in the end, you can see I'm going to run this now because this also takes quite a while because
it's quite big.
Remember, this is 25000 of features in that dataset, so it's quite big.
So you can see we got an accuracy of ninety eight point four percent.
That is really high.
It's actually remarkably high.
So let's take a look at some of this here.
Let's let's test this network now.
So to test inferences on this network, we basically just set our test territory here, ghetto image
parts here, which members names here and get the parts I would fit here.
Then we just pull a random sample from those parts that we have given it.
Here we're going to take 12 random samples here, and then we're going to loop through those 12 images
here.
So we load the image, change it into 24 by 224 sites.
That's what we expects in this case.
And then we just run it through.
To get the predictions out of it, then this is no, this is not a predictions.
Actually, this is a features.
So the futures are basically this.
So this is how we just reshape this rule here and now we can take this input.
That's the features from our CNN and pass it to a logistic regression classifier that we made previously.
And if the result is still we see it all else is on the point five.
It's a cut.
That's the biggest logistic regression gives a probability output and then we distort distorted results
here.
So you can see after that, we can visualize these results here where by printing them.
But let's actually see them on the images so we can use map plot lib here just to generate these nice
plots.
And we can see a guide dog, correct cat, correct cat, correct dog, dog.
This is actually a dog that's acting as a cat.
This is a cat.
This is a dog, dog, cat, dog, cat.
So you can see it's it's doing fairly well, as you would expect if we got 90 percent accuracy on the
training dataset and the cat under test data so that we split up here.
So now let's see how it compares to Cargill's top 10 leaderboard.
You can see that network.
We just got ninety eight point three for technically.
So you can see we're actually doing quite well.
We're in Cargo's top 10, so you can see this simple network.
The simple design is able to get achieve very, very good performance on this cat's first dog's dataset.
So I hope you enjoyed this lesson.
That's actually see if this has finished front.
Yep, it's this.
This takes a few minutes to run, actually, just just two minutes.
So you can run this code yourself and get the results I just showed you.
So thank you for watching, and I'll see you in the next lesson where we implement these two things.
Fine tuning as well as feature extraction and transfer learning.
And PyTorch without without using PI to watch lightning.
So thank you for watching and I'll see you there.
Thank you.
So I just fixed this diagram in the code because the link was broken before.
So let's go back to this.
What are we doing here?
Well, we're using the 5G network as a feature extractor, so ignoring this densely ahead as green nodes
here, we're just passing all the images into this network here and extracting the seven by seven by
512.
That's the outputs from this node.
We're going to be extracting that it would basically imagine this seven by seven by five 12 isn't,
including from the full image of all images by the CNN.
That's exactly what it is.
So we're doing this running this loop here that basically runs through all of the batches here and extracts
the features and stores that in this image, which is already here.
That's all that we're doing here.
We're just taking images, setting them up so we can pre-processed them to the network using the image
that utility is to pre process and passing it to the model predicted.
Remember, our model is just a convolutional model has not fully connected layers at the top, and that's
it.
So this takes a while to run.
So I'm leaving it here to run, but I run to the lesson as well so you can see the rest of the output.
So the image features that we get.
Remember, there are going to be a seven by seven, where is a tier, seven by seven by five 12?
It's quite a large number, but that's what we're going to be using as input to our new classifier.
So this is what it looks like.
It's quite a bigger.
You can see it actually right now.
This is a batch right here to the to by 250000, actually, that's twenty five dollars and targeting
it.
So that's what that this number means.
So you can see we have this batch of 32 images and these are the in coatings for them.
And you can see the image labels what they look like cats, first dogs for each batch.
That's why there's this array of 32 here.
So now what we're going to do, we're going to train a logistic regression classifier on those features
so we can use this list comprehension here just to get the image levels, detailed image features,
data and then we converted.
This should be can fit to Nampai areas here.
So then we can now use this as an input into our logistic regression classifier.
So we just use Trenta Splitter because remember, data set was just all those images we set up from
before those training images.
So we just split it into 80 percent, 20 percent, which is set up a logistic regression here using
the disk regression object here, said C Equal 2.1.
That's one of the parameters for logistic regression.
And in the end, you can see I'm looking to run this, and I guess this also takes quite a while because
it's quite big.
Remember, this is.
Twenty five thousand of features in that dataset, so it's quite big.
So you can see we got an accuracy of ninety eight point four percent.
That is really high.
It's actually remarkably high.
So let's take a look at some of this here.
Let's let's test this network now.
So to test inferences on this network, we basically just set up a test out a Tree Hill ghetto image
parts here, which members names here and get the parts of it here.
Then we just pull a random sample from those parts that we've given it here.
We're going to take 12 random samples here, and then we're going to loop through those 12 images here.
So we'll know the image change of that to 24 by 24 sites.
That's what widget expects in this case.
And then we just run it through a model.
Get the predictions out of it.
Then this model, this is not a predictions.
Actually, this is a features.
So the features are basically this.
So this is how we just reshape this real here and now we can take this input.
That's the features from our CNN and pass it to a logistic regression classifier that we made previously.
And if the result is still, we see a this on under point five, it's a cat.
That's the cause.
Logistic regression gives their probability output and then we just results here.
So you can see after that, we can visualize these results here where by printing them.
But let's actually see them on the images so we can use map plot lib here just to generate these nice
plots.
And we can see a got dog correct cat, correct cat, correct dog, dog.
This is actually a dog that success as a cat.
This is a cat.
This is a dog, dog, cat, dog, cat.
So you can see it's it's doing fairly well, as you would expect if we got 90 percent accuracy on the
training dataset and the cat under test data so that we split up here.
So now let's see how it compares to Cable's top 10 leaderboard.
You can see that network.
We just got ninety eight point three for technically.
So you can see we're actually doing quite well in Cargill's top 10, so you can see this simple network.
The simple design is able to get achieve very, very good performance on this cat's philstocks dataset.
So I hope you enjoyed this lesson.
That's actually see if this has finished run.
Yep, it's this.
This takes a few minutes to run, actually just just two minutes.
So you can run this code yourself and get the results I just showed you.
So thank you for watching, and I'll see you in the next lesson where we implement these two things.
Fine tuning as well as feature extraction and transfer learning.
And PyTorch without without using pretty much lightning.
So thank you for watching, and I'll see you there.
Thank you.