.pb和.h5之间的区别 [英] Difference between .pb and .h5
问题描述
张量流的. pb 格式和keras的 .h5 格式存储模型之间的主要区别是什么?有什么理由选择一个吗?
What is the main difference between .pb format of tensorflow and .h5 format of keras to store models? Is there any reason to choose one over the other?
推荐答案
具有不同特征的不同文件格式,都由tensorflow
用于保存模型(.h5
特别是keras
).
Different file formats with different characteristics, both used by tensorflow
to save models (.h5
specifically by keras
).
这是一种存储结构化数据(在这种情况下是神经网络)的方法,项目是开源,目前已由Google概述.
It is a way to store some structured data (in this case a neural network),project is open source and currently overviewed by Google.
person {
name: "John Doe"
email: "jdoe@example.com"
}
简单的class
包含两个字段,您可以使用多种受支持的语言(例如C++
,Go
)之一将其加载,解析,修改并以二进制格式发送给其他人.
Simple class
containing two fields, you can load it in one of multiple supported languages (e.g. C++
, Go
), parse, modify and send to someone else in binary format.
- 解析力极小且有效(与说出
.xml
相比),因此通常用于网络上的数据传输
当您要将模型投入生产时(例如推论),由 Tensorflow的服务使用通过网络)
- 不可知的语言-二进制格式可以由多种语言(Java,Python,Objective-C和C ++等)读取
- 从
tf2.0
开始建议使用,您可以参阅官方序列化指南 - 保存各种元数据(使用
keras
模型的情况下,优化程序,损失等)
- really small and efficient to parse (when compared to say
.xml
), hence often used for data transfer across the web - used by Tensorflow's Serving when you want to take your model to production (e.g. inference over the web)
- language agnostic - binary format can be read by multiple languages (Java, Python, Objective-C, and C++ among others)
- advised to use since
tf2.0
, you can see official serializing guide - saves various metadata (optimizers, losses etc. if using
keras
's model)
-
SavedModel
在概念上比单个文件更难掌握 - 创建
weights
所在的文件夹
SavedModel
is conceptually harder to grasp than single file- creates folder where
weights
are
您可以在此处
keras
最初用于保存模型(keras
现在正式是tensorflow
的一部分).与.pb
相比,它不那么通用,更面向数据",编程更少.
Used originally by keras
to save models (keras
is now officially part of tensorflow
). It is less general and more "data-oriented", less programmatic than .pb
.
- 用于保存巨型数据(因此某些神经网络很适合)
- 常用文件保存格式
- 所有内容都保存在一个文件中(权重,损失,与
keras
一起使用的优化程序等)
- Used to save giant data (so some neural networks would fit well)
- Common file saving format
- Everything saved in one file (weights, losses, optimizers used with
keras
etc.)
- 不能与
Tensorflow Serving
一起使用,但是您可以通过keras.experimental.export_saved_model(model, 'path_to_saved_model')
轻松将其转换为
.pb
- Cannot be used with
Tensorflow Serving
but you can simply convert it to.pb
viakeras.experimental.export_saved_model(model, 'path_to_saved_model')
如果不需要生产模型(或者距离合理很远),请使用较简单的模型(.h5
).如果要进行生产,或者只想在所有tensorflow
提供的工具中采用单一格式进行标准化,则使用.pb
.
Use the simpler one (.h5
) if you don't need to productionize your model (or it's reasonably far away). Use .pb
if you are going for production or just want to standardize on single format across all tensorflow
provided tools.
这篇关于.pb和.h5之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!