Tensorflow explains that models can be saved in three file formats: .ckpt or .hdf5 or .pb. There's a lot of documentation so it would be nice to get a simpler comparison of when to use which file format.
Here's my current understanding:
ckpt
From https://www.tensorflow.org/guide/checkpoint:
Checkpoints capture the exact value of all parameters (tf.Variable objects) used by a model. Checkpoints do not contain any description of the computation defined by the model and thus are typically only useful when source code that will use the saved parameter values is available.
So it seems like you should use cpkt for checkpointing during training when you know that your source code will be the same. Why is it recommended though over .pb and .hdf5? Does it save space? Does it include data that the other file formats do not?
pb
Also from https://www.tensorflow.org/guide/checkpoint:
The SavedModel format on the other hand includes a serialized description of the computation defined by the model in addition to the parameter values (checkpoint). Models in this format are independent of the source code that created the model. They are thus suitable for deployment via TensorFlow Serving, TensorFlow Lite, TensorFlow.js, or programs in other programming languages (the C, C++, Java, Go, Rust, C# etc. TensorFlow APIs).
The SavedModel format is .pb plus some metadata. So you should save in .pb when you are deploying a model?
hdf5
Use when saving the model weights (matrix of numbers) only?
The . pb format is the protocol buffer (protobuf) format, and in Tensorflow, this format is used to hold models. Protobufs are a general way to store data by Google that is much nicer to transport, as it compacts the data more efficiently and enforces a structure to the data.
h5 and . hdf5 are basically the same, it is a data file saved in the Hierarchical Data Format (HDF), It contains multidimensional arrays of scientific data.
The Checkpoint file is a VSAM KSDS that contains checkpoint information generated by the DTF during execution of a copy operation. The Checkpoint file consists of variable length records, one per Process that has checkpointing specified.
The PB file extension is a data file format associated to Corel WordPerfect software. PB files and WordPerfect were developed by Corel Corporation. These files contain search and index information for referencing WordPerfect documents and are used for fast lookups or backups of documents.
It seems you already know some of the differences, but just to add.
.ckpt
This is mainly used for resuming the training and also to allow users to customize savepoints and load to (ie. Highest Accuracy, Latest Trained Model, etc).
And also to create different models from different training checkpoints.
This only saves the weights of the variables or the graph therefore as you indicated you need to have full architectures and functions used.
.pb (Protobuffer)
This is the TensorFlow file format which saves everything about the Model including custom objects, this is the recommended file format to ensure maximum portability when using and exporting to different platforms (ie. Tensorflow Lite, Tensorflow Serving, etc.).
.h5 (HD5F)
This is the suggested saving format of Native Keras, which also saves everything about the model but when used in TensorFlow 2.1.0 (import tensorflow.keras) it will not save the custom objects automatically and will require additional steps to be performed.
You could read more about it in this link.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With