Next up is where we use the ImageDataGenerator.
We instantiate it and we scale our images to 1 over 255,
which then normalizes their values.
We then point it at the main directory where we see the unzipped files.
We can see that it finds all of the images, and
has assigned them to two classes, because they were two sub directories.
We'll now train the neural network for 15 epochs, it will take about two minutes.
Each epoch is loading the data, calculating the convolutions and
then trying to match the convolutions to labels.
As you can see, the accuracy mostly increases but it will occasionally dip,
showing the gradient ascent of the learning actually in action.
It's always a good idea to keep an eye on fluctuations in this figure.
And if there are too wild, you can adjust the learning rate.
Remember the parameter to RMS prop when you compile the model,
that's where you'd tweak it.
It's also going pretty fast, because right here, I'm training on a GPU machine.
By the time we get to epoch 15,
we can see that our accuracy is about 0.9981, which is really good.
But remember, that's only based on the data that the network has already
seen during training, which is only about 1,000 images.
So don't get lulled into a false sense of security.
Let's have a bit of fun with the model now and
see if we can predict the class for new images that it hasn't previously seen.
Let's go to Pixelbay, and see what we can find.
I'll search for horses, and there's lots of horses, so let's pick this one.
It's a white horse running in the snow.
I'm going to download it to my file system.
I'm now going to go back to the notebook, and
I'm going to upload the image from my file system.
And we'll see that it gets uploaded, and it's classified as a horse.
So let's try another one.
Like this one here.
Which I'll then upload to the notebook, and
we'll see that it's also classified as a horse.
I'll now go back to Pixelbay and search for person, and
pick this image of a girl sitting on a bench.
I'll download it to my file system, upload it to the neural network,
and we can see that this is also correctly classified as a human.
Let's do one more.
I'll go back to the list of results on Pixelbay, and pick this image of a girl.
As before, I'll download it to my file system and I'll upload it to the neural
network and we'll also see that it's still detects a human in the image.
Now one other thing that I can do with this script is upload multiple files and
have it classify all of them at once.
And here we can see all of the classifications.
We have four out four correct.
This notebook also includes some visualizations of the image
as it passes through the convolutions.
You can give it a try with this script.
Here you can see where a human image was convolved and
features such as the legs really lit up.
And if I run it again, we can see another human with similar features.
Also the hair is very distinctive.
Have a play with it for yourself and see what you discover.
So there, we saw a convolutional neural network create a classifier to horses or
humans using a set of about 1,000 images.
The four images we tested all worked, but that's not really scalable.
And the next video, we'll see how we can add a validation set to the training and
have it automatically measure the accuracy of the validation set, too.