1
00:00:00,615 --> 00:00:04,339
Okay, we'll now compile the model and,
as always, we have a loss function and

2
00:00:04,339 --> 00:00:05,760
an optimizer.

3
00:00:05,760 --> 00:00:08,040
When classifying the ten items of fashion,

4
00:00:08,040 --> 00:00:12,710
you might remember that your loss
function was a categorical cross entropy.

5
00:00:12,710 --> 00:00:14,830
But because we're doing
a binary choice here,

6
00:00:14,830 --> 00:00:17,870
let's pick a binary_crossentropy instead.

7
00:00:17,870 --> 00:00:20,280
Also, earlier we used an Adam optimizer.

8
00:00:20,280 --> 00:00:21,820
Now, you could do that again, but

9
00:00:21,820 --> 00:00:24,630
I thought it would be
fun to use the RMSprop,

10
00:00:24,630 --> 00:00:28,630
where you can adjust the learning
rate to experiment with performance.

11
00:00:28,630 --> 00:00:32,300
To understand learning rate and how all
that fits together, check out this great

12
00:00:32,300 --> 00:00:35,790
video from deeplearning.ai that
goes into it in a lot more detail.

13
00:00:36,840 --> 00:00:40,570
For now, I'm not going to go
into the details in this course.

14
00:00:40,570 --> 00:00:43,170
Okay, next up is the training, now,

15
00:00:43,170 --> 00:00:46,760
this looks a little different than
before when you called model.fit.

16
00:00:46,760 --> 00:00:49,570
Because now you call model.fit_generator,
and

17
00:00:49,570 --> 00:00:53,040
that's because we're using
a generator instead of datasets.

18
00:00:53,040 --> 00:00:58,444
Remember the image generator from earlier,
let's look at each parameter in detail.

19
00:00:58,444 --> 00:01:02,230
The first parameter is the training
generator that you set up earlier.

20
00:01:02,230 --> 00:01:05,220
This streams the images from
the training directory.

21
00:01:05,220 --> 00:01:08,471
Remember the batch size you used
when you created it, it was 20,

22
00:01:08,471 --> 00:01:10,284
that's important in the next step.

23
00:01:10,284 --> 00:01:13,793
There are 1,024 images in
the training directory, so

24
00:01:13,793 --> 00:01:17,010
we're loading them in 128 at a time.

25
00:01:17,010 --> 00:01:20,410
So in order to load them all,
we need to do 8 batches.

26
00:01:20,410 --> 00:01:22,690
So we set the steps_per_epoch
to cover that.

27
00:01:23,960 --> 00:01:26,680
Here we just set the number
of epochs to train for.

28
00:01:26,680 --> 00:01:31,520
This is a bit more complex, so
let's use, say, 15 epochs in this case.

29
00:01:31,520 --> 00:01:36,224
And now we specify the validation set that
comes from the validation_generator that

30
00:01:36,224 --> 00:01:37,668
we also created earlier.

31
00:01:37,668 --> 00:01:42,329
It had 256 images, and
we wanted to handle them in batches of 32,

32
00:01:42,329 --> 00:01:43,840
so we will do 8 steps.

33
00:01:45,180 --> 00:01:48,740
And the verbose parameter specifies
how much to display while training

34
00:01:48,740 --> 00:01:50,030
is going on.

35
00:01:50,030 --> 00:01:55,450
With verbose set to 2, we'll get a little
less animation hiding the epoch progress.

36
00:01:55,450 --> 00:01:56,708
Once the model is trained,

37
00:01:56,708 --> 00:01:59,618
you will, of course,
want to do some prediction on the model.

38
00:01:59,618 --> 00:02:02,870
And here's the code to do that,
let's look at it piece by piece.

39
00:02:04,250 --> 00:02:07,140
So these parts are specific to Colab,
they are what gives

40
00:02:07,140 --> 00:02:11,080
you the button that you can press to
pick one or more images to upload.

41
00:02:11,080 --> 00:02:15,328
The image paths then get loaded
into this list called uploaded.

42
00:02:15,328 --> 00:02:18,711
The loop then iterates through all
of the images in that collection.

43
00:02:18,711 --> 00:02:23,260
And you can load an image and prepare it
to input into the model with this code.

44
00:02:23,260 --> 00:02:26,770
Take note to ensure that the dimensions
match the input dimensions that you

45
00:02:26,770 --> 00:02:29,480
specified when designing the model.

46
00:02:29,480 --> 00:02:32,830
You can then call model.predict,
passing it the details, and

47
00:02:32,830 --> 00:02:35,680
it will return an array of classes.

48
00:02:35,680 --> 00:02:38,990
In the case of binary classification,
this will only contain one item

49
00:02:38,990 --> 00:02:42,330
with a value close to 0 for
one class and close to 1 for the other.

50
00:02:43,390 --> 00:02:47,300
Later in this course you'll see
multi-class classification with Softmax.

51
00:02:47,300 --> 00:02:49,740
Where you'll get a list of
values with one value for

52
00:02:49,740 --> 00:02:55,050
the probability of each class and
all of the probabilities adding up to 1.