1
00:00:00,000 --> 00:00:02,010
We've gone from
the fashion dataset where

2
00:00:02,010 --> 00:00:04,800
the images were small and
focused on the subject,

3
00:00:04,800 --> 00:00:07,110
to a new situation
where we had images

4
00:00:07,110 --> 00:00:09,615
of horses and humans
and action poses.

5
00:00:09,615 --> 00:00:12,000
We use convolutions
to help us identify

6
00:00:12,000 --> 00:00:15,030
features in the image
regardless of their location.

7
00:00:15,030 --> 00:00:17,310
This is a nice primer in solving

8
00:00:17,310 --> 00:00:20,990
some common data science
problems on places like Kaggle.

9
00:00:20,990 --> 00:00:24,020
We'll next look at an old
competition where you were

10
00:00:24,020 --> 00:00:25,820
encouraged to build a classifier

11
00:00:25,820 --> 00:00:28,115
to determine cats versus dogs.

12
00:00:28,115 --> 00:00:30,020
If you're not
familiar with Kaggle,

13
00:00:30,020 --> 00:00:33,245
it's where ML challenges are
posted often with prizes.

14
00:00:33,245 --> 00:00:36,800
Cats versus dogs was a famous
one from a few years back.

15
00:00:36,800 --> 00:00:38,570
The techniques you've just

16
00:00:38,570 --> 00:00:40,700
learned can actually
apply to that problem.

17
00:00:40,700 --> 00:00:43,160
So let's recap some
of the concepts.

18
00:00:43,160 --> 00:00:46,040
One of the nice things
with TensorFlow and Keras

19
00:00:46,040 --> 00:00:49,070
is that if you put your images
into named subdirectories,

20
00:00:49,070 --> 00:00:51,725
an image generated will
auto label them for you.

21
00:00:51,725 --> 00:00:54,785
So the cats and dogs dataset
you could actually do that

22
00:00:54,785 --> 00:00:56,270
and you've already
got a massive head

23
00:00:56,270 --> 00:00:58,225
start in building the classifier.

24
00:00:58,225 --> 00:01:00,290
Then you can subdivide that into

25
00:01:00,290 --> 00:01:03,290
a training set and
a validation set.

26
00:01:03,290 --> 00:01:05,480
Then you can use image generators

27
00:01:05,480 --> 00:01:07,415
that appointed at those folders.

28
00:01:07,415 --> 00:01:09,230
To use an image generator,

29
00:01:09,230 --> 00:01:11,255
you should create
an instance of one.

30
00:01:11,255 --> 00:01:13,580
If the data isn't
already normalized,

31
00:01:13,580 --> 00:01:15,920
you can do that with
the rescale parameter.

32
00:01:15,920 --> 00:01:17,480
You then call the flow from

33
00:01:17,480 --> 00:01:20,240
directory to get
a generator object.

34
00:01:20,240 --> 00:01:22,075
For the training dataset,

35
00:01:22,075 --> 00:01:24,335
you will then point at
the training directory

36
00:01:24,335 --> 00:01:26,990
and then specify the target size.

37
00:01:26,990 --> 00:01:30,155
In this case, the images are
an all shapes and sizes.

38
00:01:30,155 --> 00:01:33,950
So we will resize them to
150 by 150 on the fly.

39
00:01:33,950 --> 00:01:36,485
We'll set the batch
sizes to be 20.

40
00:01:36,485 --> 00:01:38,700
There's 2,000 images, so we'll

41
00:01:38,700 --> 00:01:41,175
use a 100 batches of 20 each.

42
00:01:41,175 --> 00:01:43,820
Because there are
two classes that we want to

43
00:01:43,820 --> 00:01:47,285
classify for its still stays
as a binary class mode.

44
00:01:47,285 --> 00:01:49,820
Similarly for
validation, we set up

45
00:01:49,820 --> 00:01:53,150
a generator and pointed at
the validation directory.

46
00:01:53,150 --> 00:01:55,130
We can explore
the convolutions and

47
00:01:55,130 --> 00:01:57,530
pooling and the journey of
the image through them.

48
00:01:57,530 --> 00:01:59,060
It's very similar to what you

49
00:01:59,060 --> 00:02:01,040
saw with the horses and humans.

50
00:02:01,040 --> 00:02:04,505
It has three sets of convolutions
followed by pooling.

51
00:02:04,505 --> 00:02:07,460
Of course, the image
is 150 by 150.

52
00:02:07,460 --> 00:02:09,710
Similarly, there's
a single neuron

53
00:02:09,710 --> 00:02:12,245
with a sigmoid activation
on the output.

54
00:02:12,245 --> 00:02:14,750
The summary of the layers
is very similar

55
00:02:14,750 --> 00:02:17,165
to before but note
that the size changes.

56
00:02:17,165 --> 00:02:19,625
We start with 150 by 150.

57
00:02:19,625 --> 00:02:23,390
So the convolution reduces
that to 148 by 148.

58
00:02:23,390 --> 00:02:25,850
From there, we'll go until
we end up with 17 by

59
00:02:25,850 --> 00:02:28,820
17 that we feed into
the dense layers.

60
00:02:28,820 --> 00:02:30,980
Compilation is as before.

61
00:02:30,980 --> 00:02:32,300
Now remember you can tweak

62
00:02:32,300 --> 00:02:35,735
the learning rate by
adjusting the lr parameter.

63
00:02:35,735 --> 00:02:39,680
So now to train, and we can
call model.fit generator

64
00:02:39,680 --> 00:02:41,630
and pass it
the training generator

65
00:02:41,630 --> 00:02:43,895
and the validation generator.

66
00:02:43,895 --> 00:02:46,250
That's it. As you can see,

67
00:02:46,250 --> 00:02:47,390
it's very similar to what you

68
00:02:47,390 --> 00:02:49,025
built for horses versus humans.

69
00:02:49,025 --> 00:02:51,240
So let's see it in action.