1
00:00:00,000 --> 00:00:02,250
Okay. So you've just seen how to

2
00:00:02,250 --> 00:00:04,470
get started with creating
a neural network in

3
00:00:04,470 --> 00:00:06,960
Keras that uses
the image generator to

4
00:00:06,960 --> 00:00:08,460
automatically load and label

5
00:00:08,460 --> 00:00:11,145
your files based on
their subdirectories.

6
00:00:11,145 --> 00:00:14,160
Now, let's see how we can use
that to build a horses or

7
00:00:14,160 --> 00:00:17,595
humans classifier with
a convolutional neural network.

8
00:00:17,595 --> 00:00:20,070
This is the first
notebook you can try.

9
00:00:20,070 --> 00:00:21,600
To start, you'll download

10
00:00:21,600 --> 00:00:24,465
the zip file containing the
horses and humans data.

11
00:00:24,465 --> 00:00:26,910
Once that's done,
you can unzip it to

12
00:00:26,910 --> 00:00:29,505
the temp directory on
this virtual machine.

13
00:00:29,505 --> 00:00:32,130
The zip file contain two folders;

14
00:00:32,130 --> 00:00:33,914
one called filtered horses,

15
00:00:33,914 --> 00:00:35,750
and one called filtered humans.

16
00:00:35,750 --> 00:00:37,074
When it was unzipped,

17
00:00:37,074 --> 00:00:38,915
these were created for you.

18
00:00:38,915 --> 00:00:41,540
So we'll just point a couple
of variables at them,

19
00:00:41,540 --> 00:00:43,310
and then we can explore the files

20
00:00:43,310 --> 00:00:45,200
by printing out some
of the filenames.

21
00:00:45,200 --> 00:00:47,975
Now, these could be used
to generate labels,

22
00:00:47,975 --> 00:00:51,200
but we won't need that if
we use the Keras generator.

23
00:00:51,200 --> 00:00:53,875
If you wanted to use
this data without one,

24
00:00:53,875 --> 00:00:55,230
a filenames will have the

25
00:00:55,230 --> 00:00:56,995
labels in them of course though.

26
00:00:56,995 --> 00:00:58,730
We'll print out the number of

27
00:00:58,730 --> 00:01:00,140
images that we have to work with,

28
00:01:00,140 --> 00:01:02,300
and there's a little
over 1000 of them,

29
00:01:02,300 --> 00:01:03,800
and now we can display a few

30
00:01:03,800 --> 00:01:05,480
random images from the dataset.

31
00:01:05,480 --> 00:01:08,465
Here, we can see eight
horses and eight humans.

32
00:01:08,465 --> 00:01:10,865
An interesting aspect
of this dataset

33
00:01:10,865 --> 00:01:13,400
is that all of the images
are computer-generated.

34
00:01:13,400 --> 00:01:16,145
I've rendered them to be
as photo-real as possible,

35
00:01:16,145 --> 00:01:17,960
but there'll be actually
used to classify

36
00:01:17,960 --> 00:01:19,975
real pictures of
horses and people,

37
00:01:19,975 --> 00:01:21,830
and here's a few more images

38
00:01:21,830 --> 00:01:24,050
just to show some
of the diversity.

39
00:01:24,050 --> 00:01:25,970
Let's start building the model.

40
00:01:25,970 --> 00:01:28,115
First, we'll import TensorFlow,

41
00:01:28,115 --> 00:01:29,930
and now we'll build the layers.

42
00:01:29,930 --> 00:01:31,610
We have quite a few
convolutions here

43
00:01:31,610 --> 00:01:33,470
because our source images
are quite large,

44
00:01:33,470 --> 00:01:35,285
are 300 by 300.

45
00:01:35,285 --> 00:01:37,730
Later we can explore
the impact of reducing

46
00:01:37,730 --> 00:01:40,475
their size and needing
less convolutions.

47
00:01:40,475 --> 00:01:42,560
We can print the summary
of the layers,

48
00:01:42,560 --> 00:01:44,450
and here we can see by the time

49
00:01:44,450 --> 00:01:46,340
we reach the dense network,

50
00:01:46,340 --> 00:01:49,250
the convolutions are
down to seven-by-seven.

51
00:01:49,250 --> 00:01:52,370
Okay. Next up, we'll
compile our network.

52
00:01:52,370 --> 00:01:55,580
It's using binary
cross entropy as the loss,

53
00:01:55,580 --> 00:01:58,099
binary because we're
using just two classes,

54
00:01:58,099 --> 00:01:59,480
and the optimizer is

55
00:01:59,480 --> 00:02:02,855
an RMSprop that allows us
to tweak the learning rate.

56
00:02:02,855 --> 00:02:05,360
Don't worry if you don't
fully understand these yet,

57
00:02:05,360 --> 00:02:06,500
there are links out to

58
00:02:06,500 --> 00:02:09,170
content about them where
you can learn more.