2016-04-15 19 views
1

スカラーテンソル(例えばtf.constant([4]))をpython scalar(4)に計算グラフ内で変換したい場合は、tf.eval()を使用します。tensorflow:スカラーテンソルをグラフ内のpythonスカラーオブジェクトに変換します。

+0

として一定の値を取得することができることを意味し、計算グラフの中にはテンソルしか存在しない。多分あなたの後に何を示すコード例を提供できますか? –

答えて

0

Session.run()メソッドを使用することもできます。

In [1]: import tensorflow as tf 

In [2]: sess = tf.InteractiveSession() 

In [3]: x = tf.constant(4) 

In [4]: sess.run(x) 
Out[4]: 4 
1

定数値はグラフに固定配線されているため、グラフ定義を調べることで表示できます。

IE

tf.reset_default_graph() 
tf.constant(42) 
print tf.get_default_graph().as_graph_def() 

これはあなたの

node { 
    name: "Const" 
    op: "Const" 
    attr { 
    key: "dtype" 
    value { 
     type: DT_INT32 
    } 
    } 
    attr { 
    key: "value" 
    value { 
     tensor { 
     dtype: DT_INT32 
     tensor_shape { 
     } 
     int_val: 42 
     } 
    } 
    } 
} 
versions { 
    producer: 9 
} 

を与えるこれは、計算、グラフ内のpythonスケーラーに変換すると言うとき、あなたが

tf.get_default_graph().as_graph_def().node[0].attr["value"].tensor.int_val[0] 
関連する問題