1
00:00:00,470 --> 00:00:03,250
Okay. So you just saw

2
00:00:03,250 --> 00:00:05,395
how to create a neural
network that gives

3
00:00:05,395 --> 00:00:07,480
basic computer
vision capabilities

4
00:00:07,480 --> 00:00:09,955
to recognize different
items of clothing.

5
00:00:09,955 --> 00:00:11,995
Let's now work through a workbook

6
00:00:11,995 --> 00:00:14,095
that has all of the
code to do that.

7
00:00:14,095 --> 00:00:15,850
You'll then go through
this workbook yourself

8
00:00:15,850 --> 00:00:18,175
and if you want you can
try some exercises.

9
00:00:18,175 --> 00:00:21,220
Let's start by
importing TensorFlow.

10
00:00:21,220 --> 00:00:23,650
I'm going to get
the fashion MNIST data

11
00:00:23,650 --> 00:00:26,830
using tf.kares.datasets.

12
00:00:26,830 --> 00:00:29,110
By calling the load data method,

13
00:00:29,110 --> 00:00:30,880
I get training data and labels

14
00:00:30,880 --> 00:00:32,740
as well as test data and labels.

15
00:00:32,740 --> 00:00:34,090
For more details on these,

16
00:00:34,090 --> 00:00:35,995
check back to the previous video.

17
00:00:35,995 --> 00:00:39,190
The data for a particular image
is a grid of values from

18
00:00:39,190 --> 00:00:42,650
zero to 255 with
pixel grayscale values.

19
00:00:42,650 --> 00:00:44,660
Using matplotlib, I can plot

20
00:00:44,660 --> 00:00:47,120
these as an image to make
it easier to inspect.

21
00:00:47,120 --> 00:00:49,340
I can also print
out the raw values

22
00:00:49,340 --> 00:00:50,915
so we can see what
they look like.

23
00:00:50,915 --> 00:00:52,520
Here you can see
the raw values for

24
00:00:52,520 --> 00:00:55,025
the pixel numbers
from zero to 255,

25
00:00:55,025 --> 00:00:57,310
and here you can see
the actual image.

26
00:00:57,310 --> 00:00:59,765
That was for the first
image in the array.

27
00:00:59,765 --> 00:01:03,034
Let's take a look at the image
at index 42 instead,

28
00:01:03,034 --> 00:01:05,299
and we can see
the different pixel values

29
00:01:05,299 --> 00:01:17,990
and the actual graphic.
*long pause*

30
00:01:17,990 --> 00:01:21,080
Our image has values
from zero to 255,

31
00:01:21,080 --> 00:01:24,110
but neural networks work
better with normalized data.

32
00:01:24,110 --> 00:01:26,855
So, let's change it to
between zero and one

33
00:01:26,855 --> 00:01:30,040
simply by dividing
every value by 255.

34
00:01:30,040 --> 00:01:32,150
In Python, you can
actually divide

35
00:01:32,150 --> 00:01:35,315
an entire array with
one line of code like this.

36
00:01:35,315 --> 00:01:37,645
So now we design our model.

37
00:01:37,645 --> 00:01:39,020
As explained earlier, there's

38
00:01:39,020 --> 00:01:40,820
an input layer in the shape of

39
00:01:40,820 --> 00:01:44,495
the data and an output layer
in the shape of the classes,

40
00:01:44,495 --> 00:01:45,920
and one hidden layer that

41
00:01:45,920 --> 00:01:47,870
tries to figure out
the roles between them.

42
00:01:47,870 --> 00:01:50,360
Now we compile
the model to finding

43
00:01:50,360 --> 00:01:52,625
the loss function
and the optimizer,

44
00:01:52,625 --> 00:01:54,830
and the goal of
these is as before,

45
00:01:54,830 --> 00:01:57,109
to make a guess as to
what the relationship

46
00:01:57,109 --> 00:01:59,990
is between the input data
and the output data,

47
00:01:59,990 --> 00:02:01,520
measure how well or how badly it

48
00:02:01,520 --> 00:02:03,200
did using the loss function,

49
00:02:03,200 --> 00:02:06,800
use the optimizer to generate
a new guess and repeat.

50
00:02:06,800 --> 00:02:08,480
We can then try to fit

51
00:02:08,480 --> 00:02:11,045
the training images to
the training labels.

52
00:02:11,045 --> 00:02:13,865
We'll just do it for
five epochs to be quick.

53
00:02:13,865 --> 00:02:16,580
We spend about 25 seconds
training it over

54
00:02:16,580 --> 00:02:20,245
five epochs and we end up
with a loss of about 0.29.

55
00:02:20,245 --> 00:02:22,550
That means it's pretty
accurate in guessing

56
00:02:22,550 --> 00:02:25,835
the relationship between the
images and their labels.

57
00:02:25,835 --> 00:02:28,490
That's not great, but
considering it was done in

58
00:02:28,490 --> 00:02:30,440
just 25 seconds with

59
00:02:30,440 --> 00:02:33,320
a very basic neural network,
it's not bad either.

60
00:02:33,320 --> 00:02:35,540
But a better measure
of performance can

61
00:02:35,540 --> 00:02:37,715
be seen by trying the test data.

62
00:02:37,715 --> 00:02:40,910
These are images that
the network has not yet seen.

63
00:02:40,910 --> 00:02:43,790
You would expect
performance to be worse,

64
00:02:43,790 --> 00:02:46,480
but if it's much worse,
you have a problem.

65
00:02:46,480 --> 00:02:50,140
As you can see, it's
about 0.345 loss,

66
00:02:50,140 --> 00:02:53,290
meaning it's a little bit less
accurate on the test set.

67
00:02:53,290 --> 00:02:54,700
It's not great either, but we

68
00:02:54,700 --> 00:02:56,420
know we're doing something right.

69
00:02:56,420 --> 00:02:58,975
Your job now is to go
through the workbook,

70
00:02:58,975 --> 00:03:01,850
try the exercises
and see by tweaking

71
00:03:01,850 --> 00:03:03,545
the parameters on
the neural network

72
00:03:03,545 --> 00:03:05,060
or changing the epochs,

73
00:03:05,060 --> 00:03:08,630
if there's a way for you
to get it above 0.71 loss

74
00:03:08,630 --> 00:03:12,715
accuracy on training data and
0.66 accuracy on test data.

75
00:03:12,715 --> 00:03:14,920
Give it a try for yourself.