Hi this is Jeff Heaton, welcome to Applications of Deep Neural Networks,
with Washington University. In this video we're going to see how to load and save
Keras neural networks from disk. Once you've spent all this time training a
neural network, you want to actually be able to save a copy. This is also useful
for when you save a copy of a trained neural network that you're going to
deploy to a web application or web service, like we'll see later in this
semester. For the latest on my AI course and projects click SUBSCRIBE and the BELL
next to it to be notified of every new video. Now when you save and load Keras
neural network you have several different file types that you can choose
from and two of these are textual so you can actually open up the file and look
at it in a text editor and see the components of the neural networks.
I usually don't do that but you can if you wanted to, so you could save in JSON,
there's plenty of tools that will read and write JSON so you could actually
access the saved state of the neural network directly. So YAML is a format
that only stores the structure of the neural network it does it does not store
weights. Similarly, JSON does not store the
weights either that's why I don't use those first two that often and
unfortunately those are the textual formats that are easiest to read. HDF5,
not to be confused with HDFS, which is a Spark and Hadoop format that is the
usual format that I will that I will store. These two the first two you can
use if you don't need to store the the actual weights. This demonstrates how you
would do this so here we're opening the Auto mpg data set that we had before.
We're going to build almost exactly the same neural network that we built before.
We're going to do the predictions and calculate the root mean school square
error and print that out. We're going to save that neural network to network JSON
file, which will go to the same directory as your as your workbook. We'll
say what it's JSON we'll save it as YAML and we'll save it as H5 and we can
go ahead and run that. And it's complete. Now notice the RMSE 7.17.
every time you run this you're going to get a slightly different RMSE, that's
actually a slightly bad one, we you can definitely do better than that but, it's
it's, good enough to test this feature now we're going to load it and notice
the values are exactly the same that shows that this was really saved to a
disk file and brought back. Because if you reran it and retrained it those
would be completely different values in that. That would not work very well. Now
this technique is going to be used throughout this, throughout this class. In
fact in the next section that's coming up early stopping will see that we can
program the neural network to use only as many epochs as it actually needs and it
will actually stop and save the neural network at the optimal point. Then you
can reload the optimal weights later. We're also later in this class going to
see how we can deploy a neural network to a web application or similar and
being able to save your trained neural network, is very useful so that you can
deploy it into into the cloud or into something else. Now that you've seen how
to save and load Keras neural networks we're going to look in the next video
about how to use early stopping to stop the neural network before it overfits.
Saving and loading comes into play here because the neural networks saved when
it reaches the optimal values and you need to reload it later. Thank you for
watching this video. This content changes often so subscribe to the channel to
stay up to date on this course and other topics and artificial intelligence.