2016-09-21 41 views
0

我想通過將圖形保存到文件然後運行graph_metrics.py來查看我的模型的統計信息。使用graph_metrics.py和保存的圖形

我已經嘗試了一些不同的東西寫的文件,我最大的努力爲:

tf.train.write_graph(session.graph_def, ".", "my_graph", as_text=True) 

但在這裏會發生什麼:

$ python ./util/graph_metrics.py --noinput_binary --graph my_graph 
Traceback (most recent call last): 
    File "./util/graph_metrics.py", line 137, in <module> 
    tf.app.run() 
    File ".virtualenv/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 30, in run 
    sys.exit(main(sys.argv)) 
    File "./util/graph_metrics.py", line 85, in main 
    FLAGS.batch_size) 
    File "./util/graph_metrics.py", line 109, in calculate_graph_metrics 
    input_tensor = sess.graph.get_tensor_by_name(input_layer) 
    File ".virtualenv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2531, in get_tensor_by_name 
    return self.as_graph_element(name, allow_tensor=True, allow_operation=False) 
    File ".virtualenv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2385, in as_graph_element 
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation) 
    File ".virtualenv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2427, in _as_graph_element_locked 
    "graph." % (repr(name), repr(op_name))) 
KeyError: "The name 'Mul:0' refers to a Tensor which does not exist. The operation, 'Mul', does not exist in the graph." 

是否有保存圖形的一個完整的工作示例,然後用graph_metrics.py進行分析?

這個過程似乎涉及我還沒有發現的魔法咒語。

+0

相關問題我在哪裏得到了我的基本保存方法:http://stackoverflow.com/q/36682832/86967 – nobar

回答

1

你打這個錯誤是因爲你需要與--input_layer=指定自己的輸入節點的名稱(它只是默認爲德穆爾:0,因爲這是我們在成立之初的車型之一使用):

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/graph_metrics.py#L51

graph_metrics腳本仍然是一個很不幸的工作,你可能會遇到形狀推斷的問題,但希望這應該讓你超過最初的障礙。

+0

謝謝。這是一個很好的暗示,並且讓我感動。儘管如此,我還是有太多的運動部件來猜測剩下的部分。此時,當我在應用程序中將函數調用爲函數調用時,我確實有'calculate_graph_metrics()'工作 - 如果嘗試使用圖形文件,它就不起作用。 – nobar