基於此converting-trained-tensorflow-model-to-protobuf我試圖保存/恢復TF圖沒有成功。TF保存/恢復圖失敗tf.GraphDef.ParseFromString()
這裏是保護程序:
with tf.Graph().as_default():
variable_node = tf.Variable(1.0, name="variable_node")
output_node = tf.mul(variable_node, 2.0, name="output_node")
sess = tf.Session()
init = tf.initialize_all_variables()
sess.run(init)
output = sess.run(output_node)
tf.train.write_graph(sess.graph.as_graph_def(), summ_dir, 'model_00_g.pbtxt', as_text=True)
#self.assertNear(2.0, output, 0.00001)
saver = tf.train.Saver()
saver.save(sess, saver_path)
,其與文字圖形描述產生model_00_g.pbtxt
。從freeze_graph_test.py幾乎複製粘貼。
這裏是讀者:
with tf.Session() as sess:
with tf.Graph().as_default():
graph_def = tf.GraphDef()
graph_path = '/mnt/code/test_00/log/2016-02-11.22-37-46/model_00_g.pbtxt'
with open(graph_path, "rb") as f:
proto_b = f.read()
#print proto_b # -> I can see it
graph_def.ParseFromString(proto_b) # no luck..
_ = tf.import_graph_def(graph_def, name="")
print sess.graph_def
其在graph_def.ParseFromString()
與DecodeError: Tag had invalid wire type.
我失敗的碼頭工人容器b.gcr.io/tensorflow/tensorflow:latest-devel
的情況下,這有什麼差別。
感謝 - 這兩種方式解決眼前的問題。然而,主要任務不在我這裏 - 我想存儲圖+變量,然後加載,然後在其他地方評估。這[[tensorflow/tensorflow/python/tools/freeze_graph.py'](https://github.com/tensorflow/tensorflow/tree/00440e99ffb1ed1cfe4b4ea650e0c560838a6edc/tensorflow/python/tools)看起來非常符合我的需要,但它是不是在我的碼頭圖像中,並且使用不是很清晰,只有一半的參數 - 我想我會等待0.7這個,現在切換到其他任務。 – rgr