1. 程式人生 > >tensorflow: 檢視 某個變數具體值

tensorflow: 檢視 某個變數具體值

轉載:https://blog.csdn.net/jningwei/article/details/73557938

問題

tensor詳細數值 不能直接print列印:

import tensorflow as tf
x = tf.constant(1)
print x123

輸出:

Tensor("Const:0", shape=(), dtype=int32)1

原因:

print只能列印輸出shape的資訊,而要列印輸出tensor的值,需要藉助 tf.Session,tf.InteractiveSession。

因為我們在建立graph的時候,只建立 tensor 的 結構形狀資訊 ,並沒有 執行 資料的操作。

 

解決方法

法一:

 

import tensorflow as tf
x = tf.constant(1)
with tf.Session() as sess:
    print sess.run(x)1234

輸出:

11

法二:

 

import tensorflow as tf
x = tf.constant(1)
sess = tf.InteractiveSession()
print x.eval()1234

輸出:

1
--------------------- 
作者:JNingWei 
來源:CSDN 
原文:https://blog.csdn.net/jningwei/article/details/73557938 
版權宣告:本文為博主原創文章,轉載請附上博文連結!