1
00:00:01,170 --> 00:00:04,830
Next up is where we use
the ImageDataGenerator.

2
00:00:04,830 --> 00:00:08,520
We instantiate it and
we scale our images to 1 over 255,

3
00:00:08,520 --> 00:00:11,670
which then normalizes their values.

4
00:00:11,670 --> 00:00:15,530
We then point it at the main directory
where we see the unzipped files.

5
00:00:16,690 --> 00:00:19,620
We can see that it finds
all of the images, and

6
00:00:19,620 --> 00:00:23,760
has assigned them to two classes,
because they were two sub directories.

7
00:00:28,760 --> 00:00:32,970
We'll now train the neural network for
15 epochs, it will take about two minutes.

8
00:00:34,090 --> 00:00:38,050
Each epoch is loading the data,
calculating the convolutions and

9
00:00:38,050 --> 00:00:40,920
then trying to match
the convolutions to labels.

10
00:00:40,920 --> 00:00:45,517
As you can see, the accuracy mostly
increases but it will occasionally dip,

11
00:00:45,517 --> 00:00:48,420
showing the gradient ascent of
the learning actually in action.

12
00:00:49,420 --> 00:00:53,480
It's always a good idea to keep an eye
on fluctuations in this figure.

13
00:00:53,480 --> 00:00:55,970
And if there are too wild,
you can adjust the learning rate.

14
00:00:57,230 --> 00:01:00,420
Remember the parameter to RMS
prop when you compile the model,

15
00:01:00,420 --> 00:01:02,640
that's where you'd tweak it.

16
00:01:02,640 --> 00:01:06,220
It's also going pretty fast, because right
here, I'm training on a GPU machine.

17
00:01:09,660 --> 00:01:11,360
By the time we get to epoch 15,

18
00:01:11,360 --> 00:01:15,870
we can see that our accuracy is
about 0.9981, which is really good.

19
00:01:15,870 --> 00:01:20,500
But remember, that's only based on
the data that the network has already

20
00:01:20,500 --> 00:01:24,740
seen during training,
which is only about 1,000 images.

21
00:01:24,740 --> 00:01:26,960
So don't get lulled into
a false sense of security.

22
00:01:28,160 --> 00:01:30,120
Let's have a bit of fun
with the model now and

23
00:01:30,120 --> 00:01:33,873
see if we can predict the class for
new images that it hasn't previously seen.

24
00:01:35,520 --> 00:01:38,620
Let's go to Pixelbay, and
see what we can find.

25
00:01:38,620 --> 00:01:42,080
I'll search for horses, and there's
lots of horses, so let's pick this one.

26
00:01:42,080 --> 00:01:44,440
It's a white horse running in the snow.

27
00:01:44,440 --> 00:01:46,612
I'm going to download
it to my file system.

28
00:01:46,612 --> 00:01:48,350
I'm now going to go back to the notebook,
and

29
00:01:48,350 --> 00:01:51,150
I'm going to upload the image
from my file system.

30
00:01:51,150 --> 00:01:55,310
And we'll see that it gets uploaded,
and it's classified as a horse.

31
00:01:55,310 --> 00:01:56,930
So let's try another one.

32
00:01:56,930 --> 00:01:58,580
Like this one here.

33
00:01:58,580 --> 00:02:01,010
Which I'll then upload to the notebook,
and

34
00:02:01,010 --> 00:02:03,299
we'll see that it's also
classified as a horse.

35
00:02:05,890 --> 00:02:08,980
I'll now go back to Pixelbay and
search for person, and

36
00:02:08,980 --> 00:02:11,920
pick this image of a girl
sitting on a bench.

37
00:02:11,920 --> 00:02:15,672
I'll download it to my file system,
upload it to the neural network,

38
00:02:15,672 --> 00:02:19,119
and we can see that this is also
correctly classified as a human.

39
00:02:22,319 --> 00:02:22,886
Let's do one more.

40
00:02:22,886 --> 00:02:28,670
I'll go back to the list of results on
Pixelbay, and pick this image of a girl.

41
00:02:28,670 --> 00:02:32,610
As before, I'll download it to my file
system and I'll upload it to the neural

42
00:02:32,610 --> 00:02:36,740
network and we'll also see that it's
still detects a human in the image.

43
00:02:38,056 --> 00:02:41,740
Now one other thing that I can do with
this script is upload multiple files and

44
00:02:41,740 --> 00:02:44,420
have it classify all of them at once.

45
00:02:44,420 --> 00:02:46,710
And here we can see all
of the classifications.

46
00:02:46,710 --> 00:02:47,840
We have four out four correct.

47
00:02:49,090 --> 00:02:53,190
This notebook also includes some
visualizations of the image

48
00:02:53,190 --> 00:02:55,500
as it passes through the convolutions.

49
00:02:55,500 --> 00:02:56,900
You can give it a try with this script.

50
00:02:57,920 --> 00:03:01,070
Here you can see where a human
image was convolved and

51
00:03:01,070 --> 00:03:04,210
features such as the legs really lit up.

52
00:03:04,210 --> 00:03:08,420
And if I run it again, we can see
another human with similar features.

53
00:03:08,420 --> 00:03:10,860
Also the hair is very distinctive.

54
00:03:10,860 --> 00:03:12,740
Have a play with it for
yourself and see what you discover.

55
00:03:14,320 --> 00:03:19,050
So there, we saw a convolutional neural
network create a classifier to horses or

56
00:03:19,050 --> 00:03:22,910
humans using a set of about 1,000 images.

57
00:03:22,910 --> 00:03:27,080
The four images we tested all worked,
but that's not really scalable.

58
00:03:27,080 --> 00:03:31,450
And the next video, we'll see how we can
add a validation set to the training and

59
00:03:31,450 --> 00:03:34,940
have it automatically measure
the accuracy of the validation set, too.