Hi and welcome back to the course now in this section, we're going to load a few pre-trial networks,
such as rejig and rest at Inception, mobile net and a couple others using cameras just like we did
with PyTorch.
We're going to do the same now with cameras.
So let's open this notebook and begin to listen.
So this number should load quickly.
There we go.
So these are the networks we're going to load now in this lesson, so you can take a look at this link
here.
This link will show you all the networks are available in us and is quite a bit as well, including
the efficient, fully efficient and family of networks.
And, like I explained, would apply to us less than what we're doing.
We're loading networks that have been trained on the image net dataset and Carole's gives us a nice
breakdown on the website of the accuracy so you can see what the accuracy is all for the these networks,
except for some reason for the efficient in that family.
But you can see the nice net large, which has 243 megs, which is a big network of 88 million parameters.
You can see that's quite that's the best performing network, but it's quite big.
The biggest one available actually out of all of them.
And you can see the inference time when CPU and GPU, which is quite nice to see.
So you can see the efficient.
That model is actually the slowest inference on GPUs.
It takes over a second for one image on the phone to be seven backbone efficient net.
So I mean, it's interesting to see it's good that they have it.
So let's see how we load these networks.
OK.
So to load in that network and Caris is actually quite simple.
First, we have to import it.
So we just do this and put TensorFlow that carries applications, and these are where the networks are.
So we import four video 16.
And we put it as video 16 in caps.
We can specify the same thing.
You want to get done the same lowercase, fidgety if you wanted.
And we're going to import the pre-processing image library, as well as this one here, which is specific
to BTG net and decode predictions, which is also specific to rejig.
So in PyTorch, we didn't have these these functions available.
Unfortunately, however, Keros gives us these nice pre-processed functions so that we can quickly use
them and inference them on our image or test images.
Using a loaded network like this and to load the network, all you have to do is just too big for the
weights.
So do we just image net, which I think is doing the available weights anyway and put it equal to model,
and that's a lot more effectively.
So let's run that block of code, which will take about 10 seconds because we have to connect to a virtual
machine instance.
There we go.
And it should little bit bigger and maybe a handful of seconds.
It's taking a bit longer.
But yeah, taking about five seconds to download a model.
There we go.
So we've loaded the model now and you can see 228 million parameters, which is quite big.
And no, let's get our test images here.
So we've downloaded SAS images and because I zipped them on a makeovers deleting the dirtiest or file
so that it doesn't crash when it won't go into the loop, it's always we could have done that.
That's just an easy way, but it's probably better to have it and to have it programmatically in the
could so check to see if a file is an image.
Nevertheless, we'll let's begin this lesson so our images are not stored at this path here.
Images Class one and we have our test images, the same images we used in our pie to watch pre-trained
Model S. So what we do, we just gather the file names here.
So let's get all the file names from that directory and can see them here next.
What do we do?
This is our function here, but this is the area where we actually inference on the random images,
inference and inference mode in our pre-trained model.
So it's actually quite simple and plot the results as well.
So it's quite simple, actually.
So I'm ignoring this map of lines or get back to these after what we do, CUDA file names we loaded
here.
We just load the image here using the carousel image function to image dot load image.
The full part is my part.
My part was this images plus one directory, plus the file name, which at least is here.
So if it gets for the loop, goes through each image at a time.
We specify the size we want to load images, so it's 224 for Viji.
Then we use images to array, which is not a care unprepossessing image function, and we just can convert
that image and call it excel.
Then we can squeeze or expand dimensions, which flattens the image, and then we can just run it through
the pre process.
That's a carrot and the liquorice function pre-processed that's specific to VG.
Actually, Majidi 16, I should say.
And then all we have to do now is just this is just where we display the image here.
So we load the image using OpenCV here.
Image two And that's what we plot.
I believe that.
Actually, no, I'm not seeing it.
Yeah, it is.
Yeah, this is what we plot in the code right here at the end.
And meantime, we just run the X here that we're ready to get the images for.
So we just of run the prediction model that predict on that x when this is done.
But then we use another the camera's function that's specific to be called decode predictions, and
we just take the predictions here.
We get predictions.
The predictions out of it now, decode predictions is similar to the class.
We built in PyTorch, where we just looked up the name of the actual class.
So that's what Decode Predictions does returns the actual string name for the class that Preds represents
based on the image, not classes.
And then we just plotted these new certainly seems so subplots could map of the picture that we did
above here.
This is just a figure size.
We make it nice and big.
And then we go, So let's run this.
Let's run our images now to true BGT 16, and let's see how it does.
There we go.
So let's take a look at this.
So for each output of the loop, we're actually printing this above here that's done in this line here.
Print predictions, that's what the output is.
So it just gives us the class and the probabilities as well.
So you can see it's 99 percent sure to the machine and the other class is actually quite small.
So you're probably not even close convertible and beach wagon.
So you can see that.
Let's see what it got.
Limousine basketball, college airmanship at Christmas stocking doormat, burrito, spiderweb and picket
fence.
So it got all right, except the beer.
This does seem a bit different to the to which results because if I remember correctly, the PyTorch
results for video 16, they didn't get the doormat correct.
So that's an interesting find.
You know, theoretically, you would think it would be the same as a pie touch model.
However, it could be a case where we don't actually know how long this model was trained for and the
image that we don't know the specifics.
We don't know.
They're not exactly the same width, which clearly these results represent.
So that's an interesting results so far, that pipe that Cara says that a pre-trained models.
So now let's load resonant.
Less than 50, in fact, previously entitled to be loaded resonant of 18, which is a lots, which is
a much smaller, resonant.
This restaurant has 25 million parameters, which is moderately sized and I would say still small.
And now we can just run our same code that just runs the inference of those images through the rest
of the model.
And let's see outperforms, and it performs quite well.
Let's see it got it actually got pretty much everything correct, although I would say this is a bad
model, but maybe the category is more appropriate for this.
But it got all of these images correct, which is remarkable.
So you can see Resonant 50 is quite a good network, and that should give you some intuition as to why
I see a resonate as my favorite network.
I mean, it's not good to have favorites, but I do get generally get the best results in a lot of researchers
as well.
Get the best results with resonant networks.
So let's try Inception Vietri, get our weights, get on network 23 million parameters, not too big
or too small.
Let's run this loop here that gives us the predictions for each image and then we can see Limousin basketball.
It got this wrong.
It's not a Shetland sheepdog.
It's actually got this right.
But this really got this right.
Pretty big.
Las Vegas is probably the category.
I would say.
This is the correct category for this.
So that's pretty good, although it's not perfect because they got this one wrong.
It's quite quite good, though, so let's try and move on it now.
So let's load the mobile network.
Actually, there's one thing I wanted to show you for this one.
Remember, the image size for inception is different.
It's a little bit larger.
It's 229 as opposed to 24.
So you would just have to change the target size in this limited image function to 228 299.
Sorry.
So let's sort of load image of bullet, which I've already done, and within that parameters are 2.5
million quite small.
And now we can run our inference on the images here using mobile it and we can see limousine basketball,
college and shepherds is quite good Christmas stocking.
It's no wallet.
It is a very good spider web.
It's definitely not parallel, but so mobile.
I did get the worst performance so far, but it's actually still quite good.
So let's ride this theinternet, who will?
That's a very big network.
That's not to a one.
So let's take a look and see how that performs.
This should give us the best results, but I actually don't remember if it did.
It's actually, oh, it's actually not as big as I thought.
It's a very deep network, which doesn't have that many parameters.
So let's run this and see what the results are.
So again, it's pretty decent, except for ice lolly.
They've got everything else correct, so that's also impressed with that.
It's pretty good.
That's strange.
That's no.
And that's it is basically a predator's predecessor to efficient net.
So let's see how it performs.
Actually, this is a mobile mast and thus that so it's a bit smaller.
So it may not be, I mean, to give us the best results, but let's see what it does.
So we can see it got everything right, except this the big glass here, which is giving a lot of these
networks some problems, but remarkably, everything else is correct.
So that's pretty good.
Now let's try efficient that so efficient that D7 is actually the biggest efficient network model that's
available in the US.
So let's see how it performs.
And you can see this is immediately the biggest model we've learned so far.
Actually, it might have been bigger, but this is 66 million parameters.
So let's now run this and let's see if we get perfect results with this one.
I'm excited to find out.
Hopefully, you are, too.
And yes, finally, a model that gets every class right efficient.
Let me V7 had got the big glass right spider web burrito donut, Christmas stocking, German Shepherd
college basketball limousine.
So that's quite impressive.
So one thing I would have noticed and you would have noticed, too, is that the Keros pre-trained models
do perform better than the PyTorch pre-trained models, and it may be a case where they just got they
just trained them for a longer time or maybe did some manipulations to it.
I don't know.
I'll actually dig into this and maybe put the answer up somewhere below or put it in the notebooks for
you guys if I have to find the find out.
So that basically concludes this lesson.
Well, Charisse, pre-trained models and loving them and using them.
Hopefully you enjoyed it.
And what we'll do now, we'll take a look at how we can actually get rank one or top one, the top five
percent accuracy, which is a simple metric, but it's not implemented easily in Keros and by touch.
So I've run a function that gives us the accuracy we want.
It's quite simple, actually, and I'll just show you guys in the next section.
So stay tuned for it.
Thank you.