python - 何时在 Tensorflow 模型保存中使用 .ckpt、.hdf5 和 .pb 文件扩展名?

标签 python tensorflow hdf5 tensorflow2.0

Tensorflow 解释模型 can be saved in three file formats : .ckpt 或 .hdf5 或 .pb。有很多文档,因此最好对何时使用哪种文件格式进行更简单的比较。

这是我目前的理解:

ckpt

来自 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.



因此,当您知道源代码相同时,您似乎应该在训练期间使用 cpkt 进行检查点检查。为什么推荐超过 .pb 和 .hdf5?它节省空间吗?它是否包含其他文件格式不包含的数据?



同样来自 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).



SavedModel 格式是 .pb 加上一些元数据。那么在部署模型时应该保存在 .pb 中吗?

hdf5

仅在保存模型权重(数字矩阵)时使用?

最佳答案

看来你已经知道了一些 差异 ,但只是到添加 .

.ckpt
这主要用于简历 培训并允许用户自定义保存点 负载到(即最高准确度、最新训练模型等)。
并创建来自不同训练检查点的不同模型 .
这只保存权重 因此,正如您所指出的那样,变量或图形需要完整架构 功能 用过的。

.pb (原缓冲区)
这是 TensorFlow 文件格式 这节省了 一切关于型号 包括自定义对象 ,这是推荐的文件格式,以确保在使用和导出到不同平台(即 Tensorflow Lite、Tensorflow Serving 等)时的最大可移植性。

.h5 (HD5F)
这是建议 的保存格式原生 Keras ,这也节省了 一切关于型号 但在 TensorFlow 2.1.0 中使用时(导入 tensorflow.keras)它 不会自动保存自定义对象 并将需要额外的步骤 进行。

您可以在此 link 中阅读更多相关信息.

关于python - 何时在 Tensorflow 模型保存中使用 .ckpt、.hdf5 和 .pb 文件扩展名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59887312/

相关文章:

python - 动态设置tensorflow变量的可训练性

python - 如何使用 HDF 文件(固定格式,多个键)作为 pandas 数据帧?

R 和 HDF5 问题

python - seaborn : plotting time on x-axis

python - 使用 conv1D 时输入数据和训练数据之间的维度不匹配

python - 如何在alpine容器中安装python2.6?

python - 准确度测量值 val_acc 可信吗?

python - HDFStore 更新存储的 HDF5 python pandas 数据帧

python - 使用 boto3 解析 AWS S3 中的文件

python - 将值设置为 DataFrame 切片的副本