Our final project in the course, and I want us to have a little bit of fun.
This one is going to be nice and quick, but also a ton of fun that hopefully gets you excited about
the power of machine learning.
Now, my personal opinion is that most of the machine learning moving forward is not about creating
our own models or doing really complex math and statistics, but instead it's in the ability of us to
use pre-existing models to solve business problems, to solve human problems.
And I want to demonstrate this by using a great library called Image A.I. And as you can see here,
let's make this a little bit bigger.
It's a Python library built to empower a developer to build applications and systems with self contained
computer vision capabilities.
That is, instead of us having to build a computer vision model all from scratch, we can use pre existing
tools to use something like this library to solve a problem, or maybe create an entire business around
a model that is freely accessible to us.
And I'm going to show you this awesome library that's going to do some really neat things.
So I'm going to link to this resource.
But what we're going to do is we're going to create an image recognition app where we feed it some photos
and it's going to be able to tell us exactly what that image has.
That's pretty cool, right?
Let's get started.
So if we read through the documentation, it actually has a pretty good overview of what we can do.
Now, as you can see here, we have to install a few things for us.
So let's just copy this and I'll go over what some of these do.
So we're going to copy and paste, make sure that you're using PIP version three based on your installation.
We're using TensorFlow and Cross and OpenCV, which is an image processing library and TensorFlow and
tariffs are very popular machine learning libraries.
Now we're going to install this and as this is being installed.
It's quite a bit to install.
So just a heads up that these libraries tend to be heavier.
And then we also want to install the Image API library.
So let's copy this and let's see if this is done.
Nope.
It's still gone.
Give it a bit of time.
Let's clear this and run the image.
I upgrade.
All right.
So hopefully we have these libraries installed.
And what we can do is, well, just simple image prediction.
So I've created a folder here, really smart brain that has an empty python file and three images that
I'll attach to this lesson.
We have a giraffe image, a Godzilla image, and a house image.
So let's see how we can use the image.
A library.
What we can do is say from image I we're going to use the.
Prediction module and we're going to import the image prediction.
Part of it.
Now we also want to grab these files, so I'll just do a simple import of the OS library so that I can
say execution path.
Well equal the OWS dot get current working directory that is wherever I'm running this from get to whatever
directory we're in.
So that's just saying present working directory.
Oh grab this directory for us.
So that's the execution path.
And we can instantiate the prediction image prediction.
That we just import it by saying.
Image and this should be capital I.
Let's make this a little bit bigger.
So I'm going to say.
Image prediction to instantiate it.
And in here we can do some different things.
If we go back to the library, we're using the image prediction option here.
Keep in mind that this library actually can do different things like object detection, which is really,
really cool, or video object detection.
But for now we're interested in the image prediction.
So if we go to tutorial and guide.
You'll see exactly here what we can do to do the predictions.
So let's just copy this for now and go over what it does line by line.
We have our prediction variable and we set the model type.
That is, we decide what model we want to use.
Now, this library has a few models that we can use, and these are really popular models that are already
pre built.
For example, Google Brain Team has this model that's created the Facebook I research, created this
model for image processing, and then Resnick, a very famous model by Microsoft.
Now we'll use the squeeze net because as you can see, the size of the model is quite small compared
to the other ones.
That is the downside of these models.
Sometimes they can be heavy, but the smaller the algorithm, the faster the prediction time, but the
less the accuracy.
So instead of using the resonant, let's use squeeze net.
So I'm going to change this to squeeze net.
Next is to set the model path.
So again, we're using the OS to find the model that we want to use.
We actually have to download these models if we want to use them.
So you can see here, if I click on it, I get a little download of the squeeze net.
So again, the more accurate ones, we'll just have more.
Bytes of data that you have to download.
So it's up to you.
I'm going to use the squeeze net though.
So now I get this file which I can move.
Into my project folder.
So let's go to desktop.
Go to a really smart brain.
And then plug it in here.
So again, this is a binary file that we can just use as our model.
I'm just going to copy the file path or the name so that instead of the resonant.
We'll use the squeeze net model.
And then finally, we want to load the model and then make some predictions.
If we go back to the documentation, we can make the predictions by copying this piece of code.
We see that we have the predictions and the probabilities.
That is how confident the model is in its prediction.
And we're simply saying, hey, predict image.
Let's make this a little bit smaller.
Predict image and we're going to give it the image that we want to test in our case, instead of one
dot jpeg, we'll say giraffe.
So let's say.
Giraffe dog jpeg.
And we'll keep results.
Count at five.
And then finally we do a four loop.
So for each prediction, we're going to zip the predictions and probabilities and just print out the
output that we want.
Let's actually see what this does.
I'm going to save this and run our brain.
Dot py.
Oh, I have to say, python three brain dot pie.
So we get to actually the answer here.
But I want to talk about the error that you might encounter.
So if you see over here, I get some errors in my code.
And again, this is something that depends on the machine that you're running this from.
You might have different issues, but these are mostly warning based on my library versions that we've
installed.
Again, depending on when you're watching these videos, some of these warnings might appear to you
based on, again, the TensorFlow, the open CV, the image AI libraries that we use.
Or I might even get issues with my CPU that doesn't support instructions that this binary, which is
the H five binary that we installed, does not actually support.
But in the end, we still get an answer right here.
Let's make this a little bit bigger.
We get.
It's not looking good.
It looks like 28%.
It thinks that this is a ruffed grouse.
I don't even know what that is.
Let's let's google image that a ruffed grouse.
Oh, that's really funny.
Look at that.
So it thought that this is what the image was of and it was 28% confident.
It thought it might have been a prairie chicken.
That's 10% confidence.
A cheetah, a partridge.
All right.
So it didn't really get it right, did it?
That that image does look a little confusing.
So unfortunately, that model wasn't accurate enough.
But you can see here what the code is doing, right?
The code, when we loop says, hey, I want five results.
Of your predictions.
And then I want you to grab the predictions and the probabilities, the confidence that you have in
these predictions.
And because squeeze net is not necessarily the most accurate, it didn't figure out the giraffe image.
But what about Godzilla?
That's another tough one.
Let's do the Godzilla image.
If I save and run this again, let's clear.
Again.
We're waiting.
And there we go.
We have American alligator, 46% confidence.
Does it look like an alligator?
All right.
That's not too bad, actually.
We also get the common iguana for 18% confidence.
All right, last one.
Let's do house.
If we do house here.
Save and hit run.
Hey, look of that.
We get boathouse for 58%.
By the way, I also just downloaded the Resonant.
Model, which is supposed to be a little bit more accurate, is about 100 megabytes.
So that took a bit of time.
But I want to see if the accuracy improves.
So I just changed said model type as resonant and change the path to.
Now the new model that I have.
All right.
We don't need to open that, so let's give that a go.
I'm going to run again.
You see here that it took a little bit longer than previously because it is a bigger model, but it
looks like it thinks this is either a church or a boathouse, but it's pretty sure it's a church.
All right.
It kind of looks like a church.
What about the Godzilla image?
Let's do.
Godzilla.
See what they think of that.
All right.
It's super confident that it's an American alligator or it's still not great.
But what about the giraffe?
Let's let's check out the giraffe.
Fire on this.
Oh, boy.
This is not that great either.
So as you can see, it's hit or miss.
The idea is that this is never going to be perfect.
But ideally we create a model that is useful enough to derive some sort of business outcomes or positive
business outcomes.
Now, this was just a little taste of what you can do with Python and machine learning.
The real power comes when you combine prebuilt models that big companies have already built for us to
use them to solve our day to day problems or our business problems.
And that's why Python is so popular, right?
It's the idea of the developer community.
There are so many libraries, so many tools that are given by the community to everybody who uses Python.
Python is popular because our possibilities are endless.
As you saw, there are so many career opportunities, so many different projects that you can do.
So I encourage you to explore this library, explore other libraries, and see how you can use Python
to make your life easier.
I'll see you in the next one.
Bye bye.