Android Tensorflow演示中的初始网络将模型存储为protobuf文件(tensorflow_inception_graph.pb).我想用另一个网络替换这个网络.
是否有文档或示例如何将Python中训练有素的TensorFlow网络转换为.pb?我知道TensorFlow的Saver,但这似乎用于保存中级训练状态.如果模型已经过培训,不确定它是如何工作的.
我是深度学习和Tensorflow的新手。我重新训练了一个预训练过的tensorflow inceptionv3模型为save_model.pb,以识别不同类型的图像,但是当我尝试将fie与以下代码一起使用时。
with tf.Session() as sess:
with tf.gfile.FastGFile("tensorflow/trained/saved_model.pb",'rb') as f:
graph_def = tf.GraphDef()
tf.Graph.as_graph_def()
graph_def.ParseFromString(f.read())
g_in=tf.import_graph_def(graph_def)
LOGDIR='/log'
train_writer=tf.summary.FileWriter(LOGDIR)
train_writer.add_graph(sess.graph)
Run Code Online (Sandbox Code Playgroud)
它给了我这个错误-
File "testing.py", line 7, in <module>
graph_def.ParseFromString(f.read())
google.protobuf.message.DecodeError: Error parsing message
Run Code Online (Sandbox Code Playgroud)
我尝试了很多可以找到这个问题的解决方案,并且使用graph_def.ParseFromString(f.read())函数的tensorflow / python / tools中的模块给了我同样的错误。请告诉我如何解决此问题或告诉我可以避免ParseFromString(f.read())函数的方式。任何帮助,将不胜感激。谢谢!
image-processing python-3.x deep-learning tensorflow tensorboard
我正在训练模型并保存它,现在我尝试加载但无法执行。我也在之前的帖子中看到过,但是一些参考链接不起作用,或者我尝试了一些方法,仍然无法解决问题。
代码片段:
#load model
with tf.io.gfile.GFile(args.model, "rb") as f:
graph_def = tf.compat.v1.GraphDef()
graph_def.ParseFromString(f.read())
# with tf.Graph().as_default() as graph:
generated_image_1, generated_image_2, generated_image_3, = tf.graph_util.import_graph_def(
graph_def,
input_map={'input_image' : input_tensor, 'short_edge_1' : short_edge_1, 'short_edge_2' : short_edge_2, 'short_edge_3' : short_edge_3},
return_elements=['style_subnet/conv-block/resize_conv_1/output:0', 'enhance_subnet/resize_conv_1/output:0', 'refine_subnet/resize_conv_1/output:0'],
producer_op_list=None
)
Run Code Online (Sandbox Code Playgroud)
错误
Traceback (most recent call last):
File "stylize.py", line 97, in <module>
main()
File "stylize.py", line 57, in main
graph_def.ParseFromString(f.read())
google.protobuf.message.DecodeError: Error parsing message with type 'tensorflow.GraphDef'
Run Code Online (Sandbox Code Playgroud)
注意:如果需要更多相关信息,请务必在此处添加。让我知道
python image-processing deep-learning tensorflow tensorboard