Hey everybody this is Caleb with Debb slopes and in this video we are going to train our very own core
M-L model using Core M-L and Apple's new tool create M-L and in order to do this what we're going to
do is we're going to go ahead and pull open X code 10 Bayda as you can see him running X code 10 Beta
5 in this video.
But what we're going to do is get started with a playground.
And of course it pulls up in the wrong window.
And what we're going to do is we're going to actually use a Mac OS target for this playground and we're
just going to create a blank one so save it anywhere you want.
I'm just going to call this create email and I'll save it to my desktop and we're going to go ahead
and delete everything in here that is stuff that we do not need.
But what we're gonna do is we're going to go ahead and import a library import create M-L UI and this
playground is going to essentially use the assistant editor and it's going to show a little bit of a
user interface that we can engage with to train a model that's really cool.
And thanks to Apple using metal in this particular framework we can train models extremely quickly compared
to other solutions.
So now that we have imported that framework we're going to go ahead and create an instance of M-L image
classifier builder.
So let's just go ahead and type let the builder and that's going to be an l image classifier builder
K and we're going to go ahead and instantiate that like so.
And then all we need to do is to type the builder dot show in live view and that's where that assistant
editor is going to come into play.
And let's go ahead let's actually make this a little bit bigger.
And now all we need to do is to get it to show up here in the live view is to simply run our playground
in a moment you'll see a little spinning cursor and some instructions on the screen.
So here we go it's spinning doing its thing.
And here we are.
So we have up here a basic image classifier and it asks us to drop images to begin training.
Now ahead of time I went online and I use the Web site called pixel's dot com PCX e l s because they
have non-attribute.
Royalty free images that you can use in any circumstance.
Very cool and you don't have to pay for them you don't have to attribute anybody.
You can just use them.
So what I did is I went ahead and I created two folders one called training data and one called testing
data and in machine learning when you train a model you typically will expose your model to a set of
training data.
And typically that training data is labeled.
So if we go into the training data folder you'll see there are five subfolder and they each have the
names of the animals that we want to be able to recognize.
So I went ahead and let's go into the bird folder.
I went ahead and I found 10 photos of birds.
You can see these are just all random photos of birds different angles doing different things.
Some up close some far away and these 10 photos they recommend that you have a minimum of 10.
Apple does these 10 photos are going to be our training set so we're going to basically show our model
a picture of a bird and say hey this is a bird then what it's going to do is it's going to start to
identify key features that are the same in all of these photos.
What really makes a bird as far as the digital data goes.
Then we're going to show it a bunch of pictures of cats which are so cute so cute all.
And over time it's going to be able to identify what makes a cat.
Then after it's gone through all of that training data we're going to go ahead and pass in some testing
data and these photos are completely unique.
This photo does not exist in the training data set.
This photo of a dog does not exist in the training data set.
And what that's going to do is it's essentially going to test how we have trained our model it's going
to say hey this is a photo of a bird but it's not going to tell it that it's a bird and we're going
to see how accurately it can guess what it is that's how we'll know how accurate our model is.
So let's begin by dragging our training data over into our image classifier window.
And when we do that you'll see that it's going to show a lot of information spitting out here all of
the images are going to cycle through very quickly and we're going to get a quick printout on the training
and validation accuracy for our training model.
And it looks like we did really really good.
Typically you want about 92 percent or higher accuracy and this print out basically just explains what
happened the elapsed time and the accuracy.
The coolest thing is that first and foremost the first iteration of the data it took Point 1 8 seconds.
And as you can see it was only 76 percent accurate and the was only 66 percent accurate but with another
iteration of the data it took a bit longer but it became more accurate it learned over time that time
machine learning works were exposing a computer to a bunch of data.
And it identifies similarities in that data on its own.
It's very cool and we actually have a more in-depth machine learning course in the advanced section
of the apple slope where you can learn a much deeper dive into how machine learning works.
But with that aside we are now ready to test our model.
So we're going to drag in our testing data and we'll see how the evaluation is and this evaluation is
the real test.
Is it an accurate model or not.
So drop it in and as you can see we have 100 percent accuracy in our evaluation which means that our
model is pretty dang good.
Now there is just something to note it's not going to be perfect.
Some photos maybe you know I only showed photos of a dog looking straight at the camera.
It might have trouble identifying photos where a dog is looking to the left to right.
I did my best to make sure that I had a bunch of different angles a bunch of you know different distances
so that it learned what a dog was.
But as you can see it predicted that this photo was a dog and it truly was a dog.
It predicted that this was a tiger and it was a tiger cat bird lizard.
You get the idea.
It's an accurate model it's going to work for us.
But how do we actually use this.
That's a great question.
So in order to actually take our model that we have now trained which by the way I just want to let
you know something in the other machine learning course that we have I use some other tools to train
this and it does not use metal from Apple.
It uses another framework to train the model and it took a good 10 minutes to train my model.
But this I could train in literally less than 15 seconds which is amazing.
So click this little drop down and then click on the name of your image classifier and it may take awhile
for that little editor to pop up but we'll just call this animal classifier.
And as you can see my name is there a model train using Corum.
I'm going to say a model which can identify five different types of animals.
License will give the MIT license so anyone can use it.
And I'm actually going to go ahead and save this to my desktop I'm just going to go ahead and select
that.
Open it up and click save.
And now if I go to my desktop you will see that I have myself a pretty little model right there it's
floating in space.
But unfortunately the stacks on Makower Mojave are preventing me from being able to actually pull it
over to this desktop and use it.
But we're about to drag that M-L model into an iOS app and actually use it to build the animal classifying
app that I just showed you in the previous video.
I don't know about you but I'm super excited so let's head over to the next video and let's keep learning
about how to use this core a male model.
Aasiya there.