[英]Tensorflow: how to convert a frozen model to saved model
I'm trying to convert this Frozen Model ( extension .pb) from here: 我想从这里转换这个Frozen Model(扩展名.pb):
https://www.dropbox.com/s/bb7n78hq5owyjr0/tf_model_pb.zip?dl=0 https://www.dropbox.com/s/bb7n78hq5owyjr0/tf_model_pb.zip?dl=0
To a Saved Model . 到一个保存的模型 。
Is it possible? 可能吗? Can you share the exact code to convert this pb file to saved model?
你能分享一下确切的代码来将这个pb文件转换为已保存的模型吗?
Answer first, it's possible but quite messy to do so, because all variables required for SavedModel is converted to constant or other type during freezing ckpt to pb model. 首先回答,这样做可能但非常混乱,因为在冻结ckpt到pb模型期间,SavedModel所需的所有变量都会转换为常量或其他类型。 In tf, revert 'Constant' to 'Variable' is a little bit complicated, like:
在tf中,将“常量”恢复为“变量”有点复杂,例如:
# node is a constant
node = tf.Constant([1, 2])
output_node = tf.NodeDef()
output_node.op = "Variable"
output_node.name = node.name
dtype = node.attr["dtype"].type
data = node.attr["value"].tensor
output_node.attr["dtype"].type = dtype
output_node.attr["value"].CopyFrom(tf.AttrValue(tensor=data))
See this answer for detailed info to convert constant node to some other types. 有关将常量节点转换为其他类型的详细信息,请参阅此答案 。
So, freezing SavedModel from ckpt file is the easiest and most direct way. 因此, 从ckpt文件中冻结SavedModel是最简单,最直接的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.