Okay, we'll now compile the model and, as always, we have a loss function and
an optimizer.
When classifying the ten items of fashion,
you might remember that your loss function was a categorical cross entropy.
But because we're doing a binary choice here,
let's pick a binary_crossentropy instead.
Also, earlier we used an Adam optimizer.
Now, you could do that again, but
I thought it would be fun to use the RMSprop,
where you can adjust the learning rate to experiment with performance.
To understand learning rate and how all that fits together, check out this great
video from deeplearning.ai that goes into it in a lot more detail.
For now, I'm not going to go into the details in this course.
Okay, next up is the training, now,
this looks a little different than before when you called model.fit.
Because now you call model.fit_generator, and
that's because we're using a generator instead of datasets.
Remember the image generator from earlier, let's look at each parameter in detail.
The first parameter is the training generator that you set up earlier.
This streams the images from the training directory.
Remember the batch size you used when you created it, it was 20,
that's important in the next step.
There are 1,024 images in the training directory, so
we're loading them in 128 at a time.
So in order to load them all, we need to do 8 batches.
So we set the steps_per_epoch to cover that.
Here we just set the number of epochs to train for.
This is a bit more complex, so let's use, say, 15 epochs in this case.
And now we specify the validation set that comes from the validation_generator that
we also created earlier.
It had 256 images, and we wanted to handle them in batches of 32,
so we will do 8 steps.
And the verbose parameter specifies how much to display while training
is going on.
With verbose set to 2, we'll get a little less animation hiding the epoch progress.
Once the model is trained,
you will, of course, want to do some prediction on the model.
And here's the code to do that, let's look at it piece by piece.
So these parts are specific to Colab, they are what gives
you the button that you can press to pick one or more images to upload.
The image paths then get loaded into this list called uploaded.
The loop then iterates through all of the images in that collection.
And you can load an image and prepare it to input into the model with this code.
Take note to ensure that the dimensions match the input dimensions that you
specified when designing the model.
You can then call model.predict, passing it the details, and
it will return an array of classes.
In the case of binary classification, this will only contain one item
with a value close to 0 for one class and close to 1 for the other.
Later in this course you'll see multi-class classification with Softmax.
Where you'll get a list of values with one value for
the probability of each class and all of the probabilities adding up to 1.