hi my name is Joe Hicklin I'm a senior
developer at the math works I'm going to
show you how to do transfer learning
transfer learning can be a very
practical way to apply deep learning to
your problems with transfer learning you
take a pre-existing neural net modify it
slightly and then retrain it on your
images this can produce excellent
results and it's far far easier than
designing a network from scratch and
training it yourself
in my work I need to be able to
distinguish hamburgers from hot dogs and
cupcakes and apple pie and and ice cream
as far as I know there's no network that
will do that for me so I'm going to
start with a pre-existing Network Alex
met Alex that's been trained to classify
a thousand different kinds of images and
it's been trained on over a million
images already so here I am I'm going to
start out loading Alex net and I'm going
to get the layers out of it so I can see
the parts if you look down here you can
see that Alex now has 25 layers
most of the layers are doing useful
image processing things that will work
for my system as well as for Alex net
I'm going to leave those alone but the
23rd layer has a thousand neurons in it
because Alex net classifieds a thousand
different images I'm only going to do a
5 different kinds of images so I'm going
to replace that with a network that only
has five images finally I'm going to
replace the output layer as well the
last layer of Alex that has learned Alex
Nets classifications those thousand
different classes I don't want that I'm
going to replace it with an empty layer
that's going to learn mine so now I've
got my network set up it's time to deal
with the data you don't need a million
images like Alex net was trained on but
you do need a thousand of them to get
good results I've made a folder with
five subfolders in it one for each of my
classes so there's one called apple-pie
one called cupcakes and so on and inside
each of these folders are thousand
images of the appropriate topic I've
sized these images to be the size Alex
and that expects to 27 by 227 and you'll
have to do that too if you arrange your
data like this you can use matlab's
image data store object because it
understands that structure and it will
load all the images and label them
appropriately
for you so that's what I'm doing here as
soon as I've got my images I need to
separate them into two sets most of them
are used for training but I'll save a
few of them out to test for accuracy
later so let's do that and now I'm all
set to train my network I've got to set
up a few Network parameters here I've
chosen parameters are going to work well
you can change these if you like and see
what happens and then I'm ready to train
the network that started that's going to
take five or six minutes to do its job I
have a fairly powerful GPU in my
computer so it's pretty quick your
mileage may vary all right the network's
done training the first thing we're
going to do now is see how accurate it
is we're going to ask the network to
classify the test images the images we
left out of our training set and then
we're just going to see what fraction of
those it gets right
we were 84% accurate pretty good for
five minutes of work let's try it now at
the webcam on some real food I just
happen to have some food than my desk
numbers hamburgers apple pie hot dogs
ice cream so overall it works pretty
good it's fairly robust for a lot of
these for an angles and stuff so there
we go that works better than I expected
really I simplified this demo as much as
I could but in the download will include
a second file that will have a lot more
comments and it will have some more code
to handle some situations that might
arise I've showed you how to do
classification with transfer learning
but if you need real numbers out you can
also do regression with transfer
learning well I hope I've shown you
enough to get you interested in transfer
learning so grab some snacks and give it
a go
you