2017-07-31 28 views
1

是否有簡便的方法可以打印dtype=float32的值而不需要placeholdersfeed_dict?這個過程很尷尬,需要爲每個操作單獨定義。說我有inceptionv3模型與數百名操作:Tensorflow中所有dtype = float32的打印值(權重)

op = sess.graph.get_operations() 
    for m in op : 
    print(m.values()) 

這些和他們中的一些混合:

... 
(<tf.Tensor 'pool_3:0' shape=(?, ?, ?, 2048) dtype=float32>,) 
(<tf.Tensor 'pool_3/_reshape/shape:0' shape=(2,) dtype=int32>,) 
(<tf.Tensor 'pool_3/_reshape:0' shape=(1, 2048) dtype=float32>,) 
(<tf.Tensor 'softmax/weights_quint8_const:0' shape=(2048, 1008) dtype=quint8>,) 
(<tf.Tensor 'softmax/weights_min:0' shape=() dtype=float32>,) 
(<tf.Tensor 'softmax/weights_max:0' shape=() dtype=float32>,) 
(<tf.Tensor 'softmax/logits/MatMul_eightbit_reshape_dims:0' shape=(1,) dtype=int32>,) 
(<tf.Tensor 'softmax/logits/MatMul_eightbit_reduction_dims:0' shape=(1,) dtype=int32>,) 
(<tf.Tensor 'softmax/logits/MatMul_eightbit_reshape_pool_3/_reshape:0' shape=(2048,) dtype=float32>,) 
(<tf.Tensor 'softmax/logits/MatMul_eightbit_min_pool_3/_reshape:0' shape=() dtype=float32>,) 
(<tf.Tensor 'softmax/logits/MatMul_eightbit_max_pool_3/_reshape:0' shape=() dtype=float32>,) 
(<tf.Tensor 'softmax/logits/MatMul_eightbit_quantize_pool_3/_reshape:0' shape=(1, 2048) dtype=quint8>, <tf.Tensor 'softmax/logits/MatMul_eightbit_quantize_pool_3/_reshape:1' shape=() dtype=float32>, <tf.Tensor 'softmax/logits/MatMul_eightbit_quantize_pool_3/_reshape:2' shape=() dtype=float32>) 
(<tf.Tensor 'softmax/logits/MatMul_eightbit_quantized_bias_add:0' shape=(1, 1008) dtype=qint32>, <tf.Tensor 'softmax/logits/MatMul_eightbit_quantized_bias_add:1' shape=() dtype=float32>, <tf.Tensor 'softmax/logits/MatMul_eightbit_quantized_bias_add:2' shape=() dtype=float32>) 
(<tf.Tensor 'softmax/logits/MatMul_eightbit_quantize_down:0' shape=(1, 1008) dtype=quint8>, <tf.Tensor 'softmax/logits/MatMul_eightbit_quantize_down:1' shape=() dtype=float32>, <tf.Tensor 'softmax/logits/MatMul_eightbit_quantize_down:2' shape=() dtype=float32>) 
(<tf.Tensor 'softmax/biases_quint8_const:0' shape=(1008,) dtype=quint8>,) 
(<tf.Tensor 'softmax/biases_min:0' shape=() dtype=float32>,) 
(<tf.Tensor 'softmax/biases_max:0' shape=() dtype=float32>,) 
(<tf.Tensor 'softmax/logits_eightbit_quantized_bias_add:0' shape=(1, 1008) dtype=qint32>, <tf.Tensor 'softmax/logits_eightbit_quantized_bias_add:1' shape=() dtype=float32>, <tf.Tensor 'softmax/logits_eightbit_quantized_bias_add:2' shape=() dtype=float32>) 
(<tf.Tensor 'softmax/logits_eightbit_quantize_down:0' shape=(1, 1008) dtype=quint8>, <tf.Tensor 'softmax/logits_eightbit_quantize_down:1' shape=() dtype=float32>, <tf.Tensor 'softmax/logits_eightbit_quantize_down:2' shape=() dtype=float32>) 
(<tf.Tensor 'softmax/logits:0' shape=(1, 1008) dtype=float32>,) 
(<tf.Tensor [] shape=(1, 1008) dtype=float32>,) 

有沒有一種簡單的方法,在一次打印所有這些浮點類型的值?

回答

1

您可以使用類似

from pprint import pprint 
pprint([out 
    for op in tf.get_default_graph().get_operations() if op.type != 'Placeholder' 
    for out in op.values() if out.dtype == tf.float32]) 

飼料類型的字典是標準的Python字典,使他們不應該出現的圖形操作。

編輯

要得到他們的價值觀,你需要運行它們:

out_val = sess.run([out 
    for op in tf.get_default_graph().get_operations() if op.type != 'Placeholder' 
    for out in op.values() if out.dtype == tf.float32], 
    feed_dict=my_feed_dict) 
+0

感謝@ user1735003,這將打印有'的操作只有D型= float32':這裏是我的輸出:' ... ]' 現在,我將如何能夠打印它們的值? – Amir

+0

@Amir我更新了我的答案,指出您需要在會話中運行輸出以獲取其值。 – user1735003

+0

非常感謝,@ user1735003。這回到我現在的第一個問題!我們如何定義'feed_dict'對於所有具有不同形狀的不同浮點類型是通用的:D – Amir