0
1
00:00:00,630 --> 00:00:07,560
Now, before we get started it's always good practice to have a read of the API Documentation.
1

2
00:00:07,560 --> 00:00:14,670
So in our giant list of course related links, you will find a link to developer.apple.com/
2

3
00:00:14,670 --> 00:00:22,260
documentation/create_ml. And this will tell you how CreateML works and how you
3

4
00:00:22,260 --> 00:00:28,750
could use it for Computer Vision, Natural Language, and a whole bunch of fun stuff that we can do.
4

5
00:00:28,920 --> 00:00:34,110
And once you're done, then we're going to get started applying this and learning about how to use it.
5

6
00:00:34,890 --> 00:00:41,940
So, first, before we train anything, we have to give our model some data in order to teach it what a dog
6

7
00:00:41,940 --> 00:00:45,300
looks like, what a cat looks like, and what a rabbit looks like.
7

8
00:00:45,300 --> 00:00:50,450
So for that, we're going to head over to images.google.com and we're just going to search for
8

9
00:00:50,460 --> 00:00:57,750
dog. And now we have a whole bunch of images that any human would be able to recognize is a dog, even
9

10
00:00:57,750 --> 00:01:02,820
though some of them look a little bit weird. And we're going to head over to our desktop and we're going
10

11
00:01:02,820 --> 00:01:11,100
to create a new folder. And I'm going to call this Training Data. And inside Training Data, I'm going to
11

12
00:01:11,100 --> 00:01:18,480
create another folder called Dog. Now, the label that you give to this folder is incredibly important
12

13
00:01:18,780 --> 00:01:25,380
because this is the label that the machine learning model will associate with every single image or
13

14
00:01:25,380 --> 00:01:29,400
every single piece of data you place into this folder.
14

15
00:01:29,430 --> 00:01:34,200
So that means that when in the future, you give it an image and it's an image of a dog,
15

16
00:01:34,350 --> 00:01:37,260
it will give you back this label
16

17
00:01:37,260 --> 00:01:39,950
that is the name of this folder.
17

18
00:01:39,990 --> 00:01:45,330
So depending on how you want your data to come back, you can have it as lowercase dog or you could have
18

19
00:01:45,330 --> 00:01:48,480
it as "a dog", or whatever you want.
19

20
00:01:48,570 --> 00:01:52,630
But in our case, let's just create it, like so.
20

21
00:01:52,650 --> 00:02:00,900
Now, inside this folder, I'm going to place various images of dogs. So I'm just gonna have my Finder with
21

22
00:02:00,900 --> 00:02:07,830
my Dog folder on the left, and my Google images of dogs on the right, and I'm going to have them side
22

23
00:02:07,830 --> 00:02:12,690
by side because this will make it really easy to just drag and drop images without having to go through
23

24
00:02:12,690 --> 00:02:17,130
a process of right click, save as, dragging and dropping it.
24

25
00:02:17,160 --> 00:02:21,750
So what Google Images allows us to do is to identify an image.
25

26
00:02:21,900 --> 00:02:27,270
Click drag and place it into our dog folder.
26

27
00:02:27,270 --> 00:02:34,260
And so we're going to look at all of the images that are of typical dogs, not so much of the weird dogs,
27

28
00:02:34,260 --> 00:02:38,050
like dogs with glasses because it might just confuse model.
28

29
00:02:38,160 --> 00:02:40,620
You wouldn't teach a child that this is a dog.
29

30
00:02:40,680 --> 00:02:44,420
So we're going to try and keep it to classical images of dogs.
30

31
00:02:44,490 --> 00:02:47,250
So that looks like a dog, that looks like a dog.
31

32
00:02:47,280 --> 00:02:54,540
This is you using your own human intelligence to identify all of the images that would satisfy the label
32

33
00:02:54,600 --> 00:03:02,160
dog. And as you're going through this, you know, obviously, the more data that you provide your model, the
33

34
00:03:02,160 --> 00:03:06,660
more data that you give it, the more accurate it will become.
34

35
00:03:06,660 --> 00:03:14,310
So I'm gonna keep it to maybe just 10 or 20 images in this case. But if you find in the future when you're
35

36
00:03:14,310 --> 00:03:21,410
training your own models that it's not very accurate, and we'll talk about accuracy and how to determinant
36

37
00:03:21,420 --> 00:03:22,440
later on.
37

38
00:03:22,440 --> 00:03:27,810
But if you find that it's not very accurate, it's usually because you haven't given it enough images
38

39
00:03:27,900 --> 00:03:29,080
to work with.
39

40
00:03:29,220 --> 00:03:35,190
But for our purposes, this is probably enough because we're asking it to distinguish between cat, dog,
40

41
00:03:35,280 --> 00:03:38,940
and rabbit, and those things look very different from each other.
41

42
00:03:39,330 --> 00:03:44,750
So the more similar the images you're trying to differentiate from,
42

43
00:03:44,820 --> 00:03:49,140
so for example, if you're trying to get your image recognition model to be able to know the difference
43

44
00:03:49,410 --> 00:03:57,000
between, say, a Labrador and a pug, then you will need a lot more images because they actually look quite
44

45
00:03:57,000 --> 00:03:57,930
similar.
45

46
00:03:57,930 --> 00:04:04,800
But if the classification is more broad, say, the difference between a cat and a dog, then you won't require
46

47
00:04:04,980 --> 00:04:06,430
as much data.
47

48
00:04:06,450 --> 00:04:08,290
And that's the general rule.
48

49
00:04:08,310 --> 00:04:15,840
So, now that I've got all of these images of my dogs for training, the next thing I need to do is I need
49

50
00:04:15,840 --> 00:04:23,280
to create another data set that is going to be called the Testing Data.
50

51
00:04:24,030 --> 00:04:33,330
And this folder is, again, going to contain a subfolder with the same label of dog. And inside here, I
51

52
00:04:33,330 --> 00:04:40,470
need to place some images that I haven't yet shown my machine learning model. So I'm not going to have
52

53
00:04:40,500 --> 00:04:46,950
any of the same images that I put into my Training Data, and I need to scroll down and find some new
53

54
00:04:46,950 --> 00:04:55,980
images of dogs to show my model because this Testing Data set is going to be used to validate the accuracy
54

55
00:04:56,400 --> 00:05:03,400
of our machine learning model, because they are labeled and the machine learning model can check what
55

56
00:05:03,400 --> 00:05:11,050
it thinks it is, and then looks at the right answer and evaluates how accurate it was in the process
56

57
00:05:11,050 --> 00:05:12,440
of classifying it.
57

58
00:05:12,460 --> 00:05:18,340
So we're just going to scroll a little bit further down and we're going to drag on some new images of
58

59
00:05:18,430 --> 00:05:24,430
different dogs for our machine learning model to try and test itself.
59

60
00:05:24,430 --> 00:05:31,680
And, usually, the classic ratio between Training Data set and Testing Data set is about 80 to 20.
60

61
00:05:31,700 --> 00:05:37,900
So if you had about 20 images for training, then you only need about four or five images for testing.
61

62
00:05:37,900 --> 00:05:44,910
So let's try and find some non-weird looking dogs and use it for testing our model.
62

63
00:05:44,920 --> 00:05:45,150
Okay.
63

64
00:05:45,190 --> 00:05:48,440
So I've got five images now and I'm happy with that.
64

65
00:05:48,520 --> 00:05:54,430
Now, I'm gonna go through the same process and I'm going to repeat it for the other animals that I want
65

66
00:05:54,430 --> 00:05:55,870
to teach my model.
66

67
00:05:55,870 --> 00:06:05,090
So I'm gonna have one that is Cat and I'm also going to have one called Rabbit, and we're going to repeat
67

68
00:06:05,120 --> 00:06:06,890
the exact same process.
68

69
00:06:12,260 --> 00:06:15,200
And, of course, inside our testing data set,
69

70
00:06:15,230 --> 00:06:23,900
we'll also need to have our folders for the images that are Cats and also Rabbits.
70

71
00:06:23,900 --> 00:06:31,400
And we're going to, again, find five or six images to test and evaluate the accuracy of our model.
71

72
00:06:31,400 --> 00:06:36,950
Now, it's really important when you're doing this that the labels that you give to the folders inside
72

73
00:06:36,950 --> 00:06:43,580
the testing data match the ones that you gave inside the Training Data. So you can see over here,
73

74
00:06:43,580 --> 00:06:53,480
I've got Dog, Cat, and Rabbit singular. If over here, I decide to put Dog, Cat, and Rabbits, plural, then it
74

75
00:06:53,480 --> 00:07:00,330
will confuse our model because it'll view this as a different label for a different item,
75

76
00:07:00,350 --> 00:07:07,830
so make sure that you've spelled it exactly the same way, including capitalization and all of that.
76

77
00:07:08,240 --> 00:07:17,480
And then just go ahead and add the testing data for your other animals. All right, so I've completed that
77

78
00:07:17,480 --> 00:07:26,600
process and I've now got Testing Data as well as Training Data for all three animals. And roughly, I've
78

79
00:07:26,600 --> 00:07:33,650
got about 20 images in each of the folders for the Training Data set and about five images for each
79

80
00:07:33,650 --> 00:07:36,290
of the folders in the Testing Data set.
80

81
00:07:36,800 --> 00:07:43,820
So for anyone who's ever worked with machine learning and training their own models, then you will know
81

82
00:07:43,880 --> 00:07:52,370
just how much data you normally require just performing a very simple image recognition task.
82

83
00:07:52,370 --> 00:08:01,160
And the reason why we're able to save ourselves so much time and hassle and pain of having to collect
83

84
00:08:01,490 --> 00:08:11,030
and clean and classify and label all of these pieces of data is because the CreateML framework leverages
84

85
00:08:11,120 --> 00:08:17,570
the existing artificial intelligence that Apple has been building for their photos application as well
85

86
00:08:17,570 --> 00:08:24,050
as their Siri framework, and were able to build on top of that and, essentially, stand on the shoulders
86

87
00:08:24,050 --> 00:08:30,890
of giants, and in the process saving us lots and lots of time and making this model creation process
87

88
00:08:31,190 --> 00:08:32,460
far easier.
88

89
00:08:33,410 --> 00:08:41,860
You'll also notice that when we include images for our cat or dog or rabbit, I've been pretty nondiscriminate
89

90
00:08:41,870 --> 00:08:43,130
about these images.
90

91
00:08:43,130 --> 00:08:45,130
I haven't been checking, for example,
91

92
00:08:45,290 --> 00:08:47,680
what is the format of this image.
92

93
00:08:47,690 --> 00:08:48,820
Is it a JPEG?
93

94
00:08:48,830 --> 00:08:50,220
Is it a PNG?
94

95
00:08:50,240 --> 00:08:52,200
What is the size of the image?
95

96
00:08:52,310 --> 00:08:57,380
And, again, if you've worked with machine learning before, you'll notice that they tend to have stringent
96

97
00:08:57,380 --> 00:09:00,880
requirements in terms of the sizes of images.
97

98
00:09:00,950 --> 00:09:04,610
Often, they need to be the same size, same dimensions,
98

99
00:09:04,610 --> 00:09:06,070
they need to be the same format.
99

100
00:09:06,380 --> 00:09:13,280
Whereas, again, CreateML framework takes care of all of that for us and it doesn't actually matter what
100

101
00:09:13,400 --> 00:09:15,870
size or dimension
101

102
00:09:15,890 --> 00:09:20,080
the images we use in our Training and Testing Data sets.
102

103
00:09:20,210 --> 00:09:26,690
And as long as you're using the standard format for images that's JPEG or PNG, then it will work just
103

104
00:09:26,690 --> 00:09:27,570
fine.
104

105
00:09:27,650 --> 00:09:34,400
And also you notice that all of these images are individually named, but something kind of random like download-3
105

106
00:09:34,400 --> 00:09:42,190
or image-5, and it doesn't matter the actual name of the image that you've got in here,
106

107
00:09:42,380 --> 00:09:48,260
as long as they're all inside the folder that has the label that you want, then you're pretty much good
107

108
00:09:48,260 --> 00:09:48,620
to go.
108

109
00:09:49,790 --> 00:09:55,460
So as you can see, that was a pretty pain-free process and we're going to go and move on.
109

110
00:09:55,490 --> 00:10:01,670
So now--and we now have all of the data that we need to train our model.
