1
00:00:06,090 --> 00:00:12,340
Hey everybody this is Caleb with Debb slopes and in this video we are going to train our very own core

2
00:00:12,350 --> 00:00:19,290
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

3
00:00:19,290 --> 00:00:24,660
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

4
00:00:24,660 --> 00:00:26,410
5 in this video.

5
00:00:26,640 --> 00:00:29,530
But what we're going to do is get started with a playground.

6
00:00:29,790 --> 00:00:32,260
And of course it pulls up in the wrong window.

7
00:00:32,610 --> 00:00:38,670
And what we're going to do is we're going to actually use a Mac OS target for this playground and we're

8
00:00:38,670 --> 00:00:42,000
just going to create a blank one so save it anywhere you want.

9
00:00:42,000 --> 00:00:47,430
I'm just going to call this create email and I'll save it to my desktop and we're going to go ahead

10
00:00:47,460 --> 00:00:51,130
and delete everything in here that is stuff that we do not need.

11
00:00:51,330 --> 00:00:59,550
But what we're gonna do is we're going to go ahead and import a library import create M-L UI and this

12
00:00:59,550 --> 00:01:04,170
playground is going to essentially use the assistant editor and it's going to show a little bit of a

13
00:01:04,170 --> 00:01:09,000
user interface that we can engage with to train a model that's really cool.

14
00:01:09,000 --> 00:01:17,190
And thanks to Apple using metal in this particular framework we can train models extremely quickly compared

15
00:01:17,190 --> 00:01:17,980
to other solutions.

16
00:01:17,980 --> 00:01:24,300
So now that we have imported that framework we're going to go ahead and create an instance of M-L image

17
00:01:24,300 --> 00:01:25,760
classifier builder.

18
00:01:25,830 --> 00:01:33,000
So let's just go ahead and type let the builder and that's going to be an l image classifier builder

19
00:01:33,300 --> 00:01:36,350
K and we're going to go ahead and instantiate that like so.

20
00:01:36,630 --> 00:01:43,590
And then all we need to do is to type the builder dot show in live view and that's where that assistant

21
00:01:43,590 --> 00:01:47,000
editor is going to come into play.

22
00:01:47,140 --> 00:01:50,490
And let's go ahead let's actually make this a little bit bigger.

23
00:01:50,640 --> 00:01:56,490
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

24
00:01:56,880 --> 00:02:01,670
in a moment you'll see a little spinning cursor and some instructions on the screen.

25
00:02:01,950 --> 00:02:04,980
So here we go it's spinning doing its thing.

26
00:02:05,190 --> 00:02:07,050
And here we are.

27
00:02:07,050 --> 00:02:15,390
So we have up here a basic image classifier and it asks us to drop images to begin training.

28
00:02:15,390 --> 00:02:22,860
Now ahead of time I went online and I use the Web site called pixel's dot com PCX e l s because they

29
00:02:22,860 --> 00:02:24,300
have non-attribute.

30
00:02:24,360 --> 00:02:27,420
Royalty free images that you can use in any circumstance.

31
00:02:27,450 --> 00:02:31,070
Very cool and you don't have to pay for them you don't have to attribute anybody.

32
00:02:31,080 --> 00:02:32,190
You can just use them.

33
00:02:32,190 --> 00:02:38,970
So what I did is I went ahead and I created two folders one called training data and one called testing

34
00:02:38,970 --> 00:02:45,690
data and in machine learning when you train a model you typically will expose your model to a set of

35
00:02:45,690 --> 00:02:46,400
training data.

36
00:02:46,410 --> 00:02:48,920
And typically that training data is labeled.

37
00:02:48,990 --> 00:02:54,690
So if we go into the training data folder you'll see there are five subfolder and they each have the

38
00:02:54,690 --> 00:02:57,960
names of the animals that we want to be able to recognize.

39
00:02:57,960 --> 00:03:00,730
So I went ahead and let's go into the bird folder.

40
00:03:00,870 --> 00:03:04,310
I went ahead and I found 10 photos of birds.

41
00:03:04,440 --> 00:03:10,170
You can see these are just all random photos of birds different angles doing different things.

42
00:03:10,290 --> 00:03:16,840
Some up close some far away and these 10 photos they recommend that you have a minimum of 10.

43
00:03:16,890 --> 00:03:23,550
Apple does these 10 photos are going to be our training set so we're going to basically show our model

44
00:03:23,550 --> 00:03:28,590
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

45
00:03:28,590 --> 00:03:32,630
identify key features that are the same in all of these photos.

46
00:03:32,730 --> 00:03:36,560
What really makes a bird as far as the digital data goes.

47
00:03:36,690 --> 00:03:42,820
Then we're going to show it a bunch of pictures of cats which are so cute so cute all.

48
00:03:42,960 --> 00:03:47,320
And over time it's going to be able to identify what makes a cat.

49
00:03:47,580 --> 00:03:53,130
Then after it's gone through all of that training data we're going to go ahead and pass in some testing

50
00:03:53,130 --> 00:03:55,770
data and these photos are completely unique.

51
00:03:55,770 --> 00:03:58,970
This photo does not exist in the training data set.

52
00:03:59,070 --> 00:04:02,600
This photo of a dog does not exist in the training data set.

53
00:04:02,640 --> 00:04:07,530
And what that's going to do is it's essentially going to test how we have trained our model it's going

54
00:04:07,530 --> 00:04:12,750
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

55
00:04:12,750 --> 00:04:18,750
to see how accurately it can guess what it is that's how we'll know how accurate our model is.

56
00:04:18,750 --> 00:04:24,420
So let's begin by dragging our training data over into our image classifier window.

57
00:04:24,600 --> 00:04:29,940
And when we do that you'll see that it's going to show a lot of information spitting out here all of

58
00:04:29,940 --> 00:04:35,160
the images are going to cycle through very quickly and we're going to get a quick printout on the training

59
00:04:35,190 --> 00:04:38,240
and validation accuracy for our training model.

60
00:04:38,260 --> 00:04:40,710
And it looks like we did really really good.

61
00:04:40,710 --> 00:04:48,090
Typically you want about 92 percent or higher accuracy and this print out basically just explains what

62
00:04:48,090 --> 00:04:52,260
happened the elapsed time and the accuracy.

63
00:04:52,260 --> 00:05:00,790
The coolest thing is that first and foremost the first iteration of the data it took Point 1 8 seconds.

64
00:05:01,020 --> 00:05:08,630
And as you can see it was only 76 percent accurate and the was only 66 percent accurate but with another

65
00:05:08,630 --> 00:05:15,040
iteration of the data it took a bit longer but it became more accurate it learned over time that time

66
00:05:15,050 --> 00:05:19,310
machine learning works were exposing a computer to a bunch of data.

67
00:05:19,640 --> 00:05:23,000
And it identifies similarities in that data on its own.

68
00:05:23,000 --> 00:05:28,850
It's very cool and we actually have a more in-depth machine learning course in the advanced section

69
00:05:28,910 --> 00:05:33,590
of the apple slope where you can learn a much deeper dive into how machine learning works.

70
00:05:33,590 --> 00:05:37,550
But with that aside we are now ready to test our model.

71
00:05:37,550 --> 00:05:44,330
So we're going to drag in our testing data and we'll see how the evaluation is and this evaluation is

72
00:05:44,330 --> 00:05:45,200
the real test.

73
00:05:45,200 --> 00:05:46,910
Is it an accurate model or not.

74
00:05:47,000 --> 00:05:53,750
So drop it in and as you can see we have 100 percent accuracy in our evaluation which means that our

75
00:05:53,750 --> 00:05:56,260
model is pretty dang good.

76
00:05:56,280 --> 00:06:00,060
Now there is just something to note it's not going to be perfect.

77
00:06:00,170 --> 00:06:05,510
Some photos maybe you know I only showed photos of a dog looking straight at the camera.

78
00:06:05,570 --> 00:06:10,030
It might have trouble identifying photos where a dog is looking to the left to right.

79
00:06:10,070 --> 00:06:14,870
I did my best to make sure that I had a bunch of different angles a bunch of you know different distances

80
00:06:15,170 --> 00:06:17,020
so that it learned what a dog was.

81
00:06:17,030 --> 00:06:22,280
But as you can see it predicted that this photo was a dog and it truly was a dog.

82
00:06:22,280 --> 00:06:27,640
It predicted that this was a tiger and it was a tiger cat bird lizard.

83
00:06:27,710 --> 00:06:29,010
You get the idea.

84
00:06:29,210 --> 00:06:32,070
It's an accurate model it's going to work for us.

85
00:06:32,090 --> 00:06:34,180
But how do we actually use this.

86
00:06:34,190 --> 00:06:35,300
That's a great question.

87
00:06:35,600 --> 00:06:40,490
So in order to actually take our model that we have now trained which by the way I just want to let

88
00:06:40,490 --> 00:06:46,520
you know something in the other machine learning course that we have I use some other tools to train

89
00:06:46,520 --> 00:06:49,370
this and it does not use metal from Apple.

90
00:06:49,370 --> 00:06:55,430
It uses another framework to train the model and it took a good 10 minutes to train my model.

91
00:06:55,430 --> 00:07:00,080
But this I could train in literally less than 15 seconds which is amazing.

92
00:07:00,080 --> 00:07:06,470
So click this little drop down and then click on the name of your image classifier and it may take awhile

93
00:07:06,560 --> 00:07:11,230
for that little editor to pop up but we'll just call this animal classifier.

94
00:07:11,420 --> 00:07:14,950
And as you can see my name is there a model train using Corum.

95
00:07:14,960 --> 00:07:23,930
I'm going to say a model which can identify five different types of animals.

96
00:07:23,960 --> 00:07:27,620
License will give the MIT license so anyone can use it.

97
00:07:27,860 --> 00:07:34,130
And I'm actually going to go ahead and save this to my desktop I'm just going to go ahead and select

98
00:07:34,130 --> 00:07:34,880
that.

99
00:07:34,880 --> 00:07:37,520
Open it up and click save.

100
00:07:37,730 --> 00:07:45,230
And now if I go to my desktop you will see that I have myself a pretty little model right there it's

101
00:07:45,230 --> 00:07:46,410
floating in space.

102
00:07:46,460 --> 00:07:51,950
But unfortunately the stacks on Makower Mojave are preventing me from being able to actually pull it

103
00:07:51,950 --> 00:07:54,070
over to this desktop and use it.

104
00:07:54,110 --> 00:08:01,070
But we're about to drag that M-L model into an iOS app and actually use it to build the animal classifying

105
00:08:01,100 --> 00:08:03,780
app that I just showed you in the previous video.

106
00:08:03,800 --> 00:08:08,480
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

107
00:08:08,690 --> 00:08:10,790
about how to use this core a male model.

108
00:08:10,850 --> 00:08:11,390
Aasiya there.
