Enter the URL of the YouTube video to download subtitles in many different formats and languages.
JASON MAYES: So the next\nquestion you might be wondering
is, how on Earth do\nyou train such systems?
And that's a really\ngreat question.
Now, I know you all work in\nmany different industries
so feel free to\nadapt the following
But let's do a\nthought experiment
and pretend we are trying to\nmake a web-connected system
for farmers who are\ntrying to classify apples
and oranges to speed up the\ndelivery of the picked fruits
that are currently\nmixed together
and need to be sent to\nthe right destinations.
Now, the first\nthing you need to do
is identify the features\nor attributes of the fruits
Let's take color and weight as\nan example just like before.
Both are easy to measure and\ncan be represented numerically.
You can use digital weighing\nscales and color values
from a webcam that would\nallow you to do this.
Now, going back to\nour high school maths
if you were to sample\nsome apples and oranges
and plot these values on\na scatter chart as shown
you can see here that\nthe red and green apples
fall into the red and green\nspectrums on the x-axis
of this graph and tend\nto cluster together
with a similar weight\nvariance in the y-axis.
The oranges, as they're super\njuicy, tend to be heavier
Now, if you can draw a line\nthat separates the oranges
from the apples, you can now\nhave some degree of certainty
decide what fruit something is\nsimply by plotting its feature
If it's above the line,\nit's most likely an orange.
If it's below, it's\nprobably an apple.
You have essentially learned\nhow to classify the fruits.
So if you can get\na piece of software
to define the equation\nof this line by itself
you can get a computer to then\nlearn to classify fruits too.
And this is the essence of\nwhat machine learning is
Essentially, you're just\ntrying to figure out the best
possible way to separate\nout the example data, such
that for a new\nunseen example, you
have the best chance of\nclassifying it correctly.
But what if you had\nchosen bad features?
Let's take ripeness\nand number of seeds.
Here, the plot is\nless useful to us.
There is no straight\nor even curved
line that would allow us to\nseparate these data points.
You can't really learn\nfrom this data alone.
And you might be\nthinking, but, Jason
why would you choose such\nobviously bad features
And sure, with this\ntrivial example
it's quite clear that\nthis would be unwise.
But what about\nthose medical scans
we spoke about earlier\nin the course that
How do you define\nfeatures for that?
And what if you had\nmore than two features?
Previously, you\nhad two features
so you used a two-dimensional\nchart to separate the data.
If you had three features,\nyou would need a 3D chart
Here, a weight dimension\nis added to our previously
And now, you can use a plane\nor a rectangle in 3D space
if you will, to separate\nthe oranges from the apples.
Hopefully, in this\nimage, you can
see that the oranges are now\nfurther back in the weight
axis, making them\nseparable from the apples.
But it turns out that even three\ndimensions is typically not
enough for most machine\nlearning problems.
It's not unusual to have\ntens, hundreds, thousands
even millions in\nthe case of images
As humans, you'll struggle\nto visualize anything higher
However, for a computer,\nthe mathematics
works out just the same\nand is capable of doing
Instead of using a\nplane, you actually
use something called a\nhyperplane, which simply means
one dimension less than\nthe number of dimensions
that you have, allowing\nus to split the data
just like you did here,\nbut by using more features
and attributes, which\ncan sometimes lead us
Now, when you're working\nwith supervised learning
there are typically\ntwo types of problems
First is a\nclassification problem.
What thing is represented\nby the inputs provided?
Is it a cat or a\ndog, for example?
You're trying to predict a\nspecific class from a number
Second is a regression problem.
This is where you're trying\nto predict some number
For example, what is the\nprice of a house if it's
You can see visually here how,\nin these trivial examples
a single straight line is used\nto solve both types of problem.
But in the first\ninstance, it separates
out the data, and\nthe second, the line
itself is used to\npredict the output value.
So let's say you've got a\ndog, and you've got a mop.
It should be pretty easy\nto find the differences
between these two images, right?
It turns out, in the\nreal world, there
are edge cases that can overlap.
Even I as a human\nneed to double-check
And the reason I\nbring this up is
to raise awareness about\nbias in training your data.
One of the biggest\nchallenges you will face
is collecting\nenough training data
that's truly representative of\nall the different situations
you might encounter\nin the real world
like the edge\ncases you see here.
And if you don't do\nthis, then there's
a good chance that the\nmachine learning system
will fail in these cases too.
Imagine you wanted\nto recognize cats.
You might need 10,000 images\nof different breeds of cats
at different stages of their\nlife, kitten versus adults
different fur patterns,\ndifferent colors, all of which
are taken at different angles\nand lighting conditions
even indoors versus\noutdoors, in order
to be able to\ntrain a system that
understands the essence of\nwhat cat pixels really are.
Now, the other thing I'd\nlike to point out here
is that data is not always\nin the form of imagery.
I used that in my slides\nas it's easy to view
but remember, input data\nto train an ML system could
be tabular data, text, sensor\nrecordings, sound samples
or pretty much anything\nyou want to classify
so long as it can be represented\nnumerically to be input
So now you have a high-level\nappreciation for what's
Let's focus some more on\ngathering data and trying it
For this, you'll learn\nhow to use a website known
This site was made by\nsome friends at Google
and is powered by a\nmachine learning library
for JavaScript, which is\nknown as TensorFlow.js
which we'll learn more about\nlater on in the course.
Now, this site is great for\nprototyping, and in our case
to illustrate the importance\nof good quality input data.
So go ahead, pause\nthe video, and open
teachablemachine.withgoogle.com\nin a new window
and place that\nwindow side by side
so you can follow along as\nI show you how to use it.
I'll wait for you to do that.
And remember to hit Play when\nyou're ready to continue.
All right, so to\nkick things off
let's hear from the creators\nof Teachable Machine
to give us the overview\nbefore we use it together.
SPEAKER 1: People are training\ncomputers and creating machine
learning models to explore\nall kinds of new ideas
SPEAKER 1: --to understand\nthe world, to play--
But machine learning is\npretty intimidating to get
into, so we've been\nwondering, what if it wasn't?
With Teachable\nMachine, we set out
to make it easier for anyone\nto create machine learning
models without needing to write\nany machine learning code.
When it first\nlaunched in 2017, it
allowed everyone to\nget a feeling for what
But now, Teachable\nMachine puts the power
of machine learning\nin your hands
allowing you to save\nyour models and use them
SPEAKER 3: So let's say you want\nto build a model to recognize
You just open up the site,\nrecord samples of you
and samples of your\ndog, click Train
and you instantly\nhave your own machine
learning model, which you\ncan use in your sites, apps
You can upload your model to\nhost it online or download
it to work entirely on device.
SPEAKER 1: With\nTeachable Machine
you can create custom models\nfor all sorts of things--
--or even poses, personalized\nmachine learning models
for the things\nthat matter to you.
And folks have already\nbeen trying it out
using Teachable Machine\nin their own experiments
solving problems in\ntheir communities--
SPEAKER 1: --or\neven just at home.
Start creating and see\nwhere your ideas take you
So now you know what\nthis system can do.
Follow along with me to\nmake your very first machine
learning model to recognize\nany object in your room.
OK, so when you head over\nto Teachable Machine
you should see a website that\nlooks something like this.
As you can see, it supports many\ndifferent types of projects.
First is image recognition, the\nsecond is audio recognition
and the third is\npose recognition.
All of these are\nmodels that are powered
by TensorFlow.js,\nwhat you'll learn
Now, today, we're going to\nfocus on image recognition
just to teach you the\nbasics of gathering data.
So click on that and then click\nStandard image model, as shown.
You should then see a screen\nthat looks something like this.
On the left-hand side, we've got\nthe objects you want to detect.
At the moment, they're called\nClass 1, Class 2, and so on.
Let's give it a more\nmeaningful name.
So the first thing,\nI'm going to call
Jason," and the\nsecond thing, I\'m
going to call\n"Bottle," as shown.
OK, so we now can\nclick on Webcam
enable access to our webcam\nif it's our first time using
this site, and if\nyou allow access
you should then see your\nwebcam come into view.
Now, if you've got\nmultiple webcams
you can click on the dropdown\nto select the right one.
And now, we're going to\nhold to record some images
Now, this one is\nJason, so that's me.
And, of course, you're going\nto record your own things over
there, so feel free to\nchange your names as needed.
And now I'm going to try and\nget some sample images of myself
Note, I move my head around\nto get some variation as well.
I've got about 43\nimages, and that's great.
We now go to Bottle,\nclick on Webcam
and here, I'm going to try and\nrecognize this bottle instead.
So I'm going to try and get\nthe same number of images
And that's important\nbecause if you
have too many of one class,\nstatistically speaking
the machine learning\nwill think that that's
more likely to\nappear just naturally
So it might learn\njust to predict
And, of course, when it's\ntraining, it would be right 90%
So it's important to have\nroughly the same number
of examples for\nyour training data.
So let's try and\ndo the same thing
here with the bottle nice\nand close to the webcam
and get roughly the same\nnumber, 40-something images.
Now, let's go ahead\nand train our model.
And what's happening now is\nthat, live in the browser
TensorFlow.js is going to\nretrain the model so it
can distinguish between these\ntwo different object types.
And you can see, it's\nalready finished.
And you now got a preview\non the right-hand side of it
Now, you can see\nright now that it
says "Jason" with\n100% confidence, which
And if I bring the\nbottle into view
it switches to "Bottle"\nwith 100% confidence, which
And this is very usable for\na prototype, for example.
Now, if this is good\nenough for your needs
you can actually click on\nExport Model at the top
here, click on Download,\nand then click on
this button here to\ndownload the model files.
This will contain\nthings like a model.json
and some binary files you can\nhost on your website to then
And, of course, we've given you\nsome example code down below
here that you can\nuse to get started.
But don't worry\nabout that for now.
We'll be teaching you all\nabout how to code later on.
So for now, let's go back\nand focus on training data.
Now, I just trained\na system that
recognizes the difference\nbetween me and a bottle
But let's try other\nbottles to see if it
manages to recognize those too.
It seems to be recognizing\nthat shape is important here.
And let's just try one with\na different color as well.
And again, it gets that that\nis actually a similar thing.
However, if I bring into view\nthis kind of jar-like object
it's not quite as sure,\nbut it gets to the 90s
So we might want\nto train a system
to be better at recognizing\njars, for example.
So in order to do that, we can\nadd another class on the left
here, maybe call\nit "Jar," like so.
And now we can add\ntraining data for that.
So let's go ahead and get\nroughly 45 images of this jar
Let's open that up like so and\nget roughly the same number
Hit on retrain to train the\nmodel once again, between three
And now you can see we've got\nJason, Bottle, or Jar showing.
And if I show it the\njar, it's now 100%
confident that that is\na jar, which is correct.
And let's go ahead and\ntest the bottles again.
It's always good\nto retest things.
The bottle is 100%\nconfident there.
And let's bring that green\none again back into view.
It actually think this is a jar.
Well, looking at\nthese two objects
you can see that they're\nboth green, or a lot of green
contained within them, right?
So what's happened is that\nit thinks that a jar is just
some green object, whereas\na bottle is just kind
So in order to get\naround this, you're
going to have to add more\ntraining data to your examples
to improve the\naccuracy and so it
knows that this is, in\nfact, a jar versus a bottle.
So what are we going to do here?
Well, for this bottle\nover here, we're
going to go back to the bottle\ntraining data, click on Webcam
and we're going to add some\nexamples of this bottle
to the scene so that\nwe know that this
So let's go ahead, put that in\nview, and click Hold to Record
Now, because I've got\n84 images of Bottle
I need to go and get\nsome more training data
Oh, let's move the\nbottle out of view
because that would be\ncontaminating my data.
I'm going to click Train\nModel and get some more of me.
So now I'm going to click\nHold to Record to get
And now let's do the same\nthing for Jar as well.
So open up the webcam for Jar\nand put this back into view
And let's get some variation\nof the jar and get roughly--
OK, that should be close enough.
So now, if I click\non Train Model here
we're going to have a\nlot more training data.
It might take a bit more\ntime, but we should now
get a more reliable\noutput model that
can distinguish these things.
Bottle number 1,\nclose enough to 100%.
Bottle number 2,\nstraight in there, 100%.
Bottle number 3, which\nwas the one that was
And now, if we try the\njar, hopefully it still
remembers that this\nthing over here is a jar.
And as you can see, we've now\ntrained a much more robust
So go ahead and explore yourself\nwith objects in your room
to see what you can recognize\nand what causes problems
As you experienced, the machine\nlearning model you created
was as good as the data\nthat you presented to it.
The more data you\nuse, the better
it can be at generalizing,\njust like the image
All of these\nobjects are bottles
but if you only use\none type in training
the model could\nstruggle to detect
Instead of learning that color\nwas the distinguishing feature
it might learn that shape\nwas more important, leading
As you saw, in this use case,\nwhere images were the input
you do not have\ncontrol over what
features it decides\nare important
as it will decide by itself,\nbased on the data presented
what distinguishing features\nprovide the best data
And by providing\nvaried inputs, it
has less chance of\nchoosing wrong features.
In all the images\nI just showed you
I used my hand to\nhold the object.
In this case, it could learn\nthat the hand is the thing
to recognize and not\nthe object itself.
Technically speaking,\nit would be correct
as my hand existed in every\nsingle image that we showed it.
But as a human, you\nknow that this was not
Continue to explore using\nTeachable Machine to see what
edge cases you can find that\nlead to issues for the object
Maybe try for other objects\ntoo if they're similar