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