Okay. So you just saw
how to create a neural network that gives
basic computer vision capabilities
to recognize different items of clothing.
Let's now work through a workbook
that has all of the code to do that.
You'll then go through this workbook yourself
and if you want you can try some exercises.
Let's start by importing TensorFlow.
I'm going to get the fashion MNIST data
using tf.kares.datasets.
By calling the load data method,
I get training data and labels
as well as test data and labels.
For more details on these,
check back to the previous video.
The data for a particular image is a grid of values from
zero to 255 with pixel grayscale values.
Using matplotlib, I can plot
these as an image to make it easier to inspect.
I can also print out the raw values
so we can see what they look like.
Here you can see the raw values for
the pixel numbers from zero to 255,
and here you can see the actual image.
That was for the first image in the array.
Let's take a look at the image at index 42 instead,
and we can see the different pixel values
and the actual graphic. *long pause*
Our image has values from zero to 255,
but neural networks work better with normalized data.
So, let's change it to between zero and one
simply by dividing every value by 255.
In Python, you can actually divide
an entire array with one line of code like this.
So now we design our model.
As explained earlier, there's
an input layer in the shape of
the data and an output layer in the shape of the classes,
and one hidden layer that
tries to figure out the roles between them.
Now we compile the model to finding
the loss function and the optimizer,
and the goal of these is as before,
to make a guess as to what the relationship
is between the input data and the output data,
measure how well or how badly it
did using the loss function,
use the optimizer to generate a new guess and repeat.
We can then try to fit
the training images to the training labels.
We'll just do it for five epochs to be quick.
We spend about 25 seconds training it over
five epochs and we end up with a loss of about 0.29.
That means it's pretty accurate in guessing
the relationship between the images and their labels.
That's not great, but considering it was done in
just 25 seconds with
a very basic neural network, it's not bad either.
But a better measure of performance can
be seen by trying the test data.
These are images that the network has not yet seen.
You would expect performance to be worse,
but if it's much worse, you have a problem.
As you can see, it's about 0.345 loss,
meaning it's a little bit less accurate on the test set.
It's not great either, but we
know we're doing something right.
Your job now is to go through the workbook,
try the exercises and see by tweaking
the parameters on the neural network
or changing the epochs,
if there's a way for you to get it above 0.71 loss
accuracy on training data and 0.66 accuracy on test data.
Give it a try for yourself.