hi there
in this video i will do some
benchmarking of tensorflow
without a gpu i'll be training an image
classification model
that i have developed in a previous
episode
with my amd ryzen 5900x cpu
the amd ryzen 5900x cpu
has 12 cores and 24 threads and it's a
great cpu
all around perfect for someone who wants
to dip their toes into deep learning
i will try to complete the training of
the same model with my nvidia
rtx 3070 gpu which has 5888 cuda cores
and i'm expecting of course to beat my
amt ryzen 5900x cpu
by a big margin because gpus are just
faster than cpus
when handling lots of matrix
calculations
but i'm going to be open-minded you
never know one of the reasons i'm a bit
open-minded is that
i saw on github an open issue
regarding the rtx 3090 being slower than
the nvidia gtx 1080i
for predictions in this case with res
dead this might be because
of tensorflow itself which is still
implementing
kuder 11.2 and not yet taking full
advantage of the ampere architecture
but of course this is just a result
between gpus
in general a gpu is going to always be a
lot faster than a cpu
if not there must be something wrong
what are we waiting for let's get
started
let's create a new environment two point
five
sometimes four two five let's start
gypto lab so i have a notebook here
which i created
in a previous episode and this notebook
actually trains an image classification
model to basically to check if
a painting is of the nativity uh or not
so you can check it out the videos i'll
put that into the description
if you're curious so we're going to run
this notebook using
the cpu only so i'm just going to start
it now
this is the first place where we're
going to do some training for 10 epochs
and see how fast this goes
case finished the first training
so accuracy on the test data set is 67
0.67 it's not too bad
okay now 25 epics and see
see how long it takes
so the training completed
not too bad now we're going to do
transfer running
okay so 25 epics with transfer learning
this is a much bigger model and it's
going to take a bit longer
it has completed the training and
let's just check so the training looks
good actually
so the the loss goes down which is what
we want to see
on the validation on the training that
said it always happens
it goes down because a neural network is
very
it's very good for for fitting against
the data
in which it's trained so let me just see
if i can gather some more information
we can see that for transfer learning it
took like
between 11 and 13 seconds per epoch
to train each step in the previous
models
without using transfer learning and this
is training a model from scratch it
takes 161 milliseconds per step which is
quite good
and this one takes about 157
milliseconds
so we can see that because we are using
a bigger model it takes a lot longer
in this case we're using the exception
architecture which is trained on
imagenet
okay we can see how long it takes to do
uh fine tuning okay
so it took two seconds per step
fine tuning and then 47 seconds per
epoch
compared to 11 seconds per epoch here
okay this is just to check how good the
predictions are
predicted is p ground troop is gt
in this case it's not even activity it
seems too much max is good
good no this one is bad so in total has
a
72 accuracy
okay it's finished i'm done the testing
train the this custom image
classification model without a gpu
and now let's see how much improvements
we can get
you can see now it's able to detect the
gpu which is good
okay so that's very good now i'm going
to run
again this notebook and see how how
much faster the training is compared to
before
i need to start the from the right step
so i should start from here
so here i'm compiling the module
now i'm going to run the model see
before it took 1567 milliseconds
i'm using the gpu at the moment for
recording this so i might have to switch
it off i'm just going to try and see
what happens
if i don't do that
okay it still works as you can see it's
a lot faster
before it was doing in milliseconds now
it's doing almost like in zero seconds
so 11 milliseconds per step okay
but this is not a lot of data so it
doesn't take very long and the model is
very small
but it's considerably faster than
my amd ryzen 5900
okay now it's the second
attempted training it's very fast
okay let's do the transfer running this
is the one where it's
supposed to take a bit longer so it's
taking
one second per step and sorry one second
per epoch and before
it was taking 11 seconds
and notice there is a the first epoch
takes a bit longer because this is a
startup time for tensorflow this is
actually a known issue
takes a bit of time so very quick
much quicker than my cpu as you would
expect look at this this is like sweet
spot of
this is what you want to see in terms of
validation loss going down a conjunction
with the training loss
so here we're running again the training
with fine tuning
i am using uh the gpu as well for
recording my voice
because i'm using rtx broadcast so
i think this is actually going to be
quicker if
i don't run this application at the same
time as i i
run the training but you know you can
see it's actually reasonably fast
no so before it was taking 44 seconds
per epic
now it's taking nine seconds for the
first one and then five seconds for the
the next one so it's much faster as you
would expect and that's about
it even though i have a very good cpu
it's a ryzen 5900 you know i tried to
train
the same model in google cloud without
the gpu and it took forever
this cpu is already uh doing a lot you
know
for a first cpu is actually not bad for
what it's
it's trying yeah compared to google
cloud at least the cpu is very good
as you would expect all right and that's
about it
i hope you enjoyed this video and hope
see you again soon don't forget to click
the like button by the way and
happy coding