Saving and Loading a TF Model
Learn to save a DL model in HDF5 format using Keras, and load existing HDF5 models from storage.
Large DL models working on a huge amount of data can take days or even weeks to train. To save time, we need to save/load these models to/from the disk or a storage device. We can save Keras model architectures as well as model weights to files and load them to make predictions. The portable HDF format stores model weights and the JSON format stores the model architecture. We can either save the model weights and architecture separately in different files or together in a single file. Let’s learn to store and load model weights and architectures.
Hierarchical data format
Hierarchical data format (HDF) facilitates the storage and portability of large, multidimensional numeric arrays. Therefore, it can store well-organized scientific data. Keras usually uses HDF format to store model weights. HDF5 is the common format for storing model weights that simplifies the file structure to have only two types of objects:
Typed multidimensional arrays for datasets and weights.
Groups/container structures that hold datasets.
JSON
JavaScript Object Notation (JSON) is a textual format for representing and storing structured data in a hierarchy. It’s an easy-to-understand format that uses the object syntax of the
The curly braces represent a JSON object. A colon separates keys from values and a comma separates each key-value pair. For instance, in the following program, a hierarchical data of employees is shown where "employees"
is a key that contains information about employees. Next in the hierarchy, each employee has the keys, "name"
and "email"
, whose values are given next to the keys.
Get hands-on with 1200+ tech skills courses.