2016-06-30 4 views
1

私はドキュメントon core graph structuresを読んできました.TensorFlowが実際にやっていることとドキュメント(私が誤解している場合を除き、私が前提にしていない限り)とは異なると思われます。TensorFlowには、操作を含め、すべてがTensorですか?

ドキュメントには、Operation objectsTensor objectsと記載されています。そのような例を示していますので、いくつか作成し、Pythonにどのような型があるかを尋ねました。まず、定数を行います:

c = tf.constant(1.0) 

print C#Tensor("Const_1:0", shape=(), dtype=float32) 
print type(c) #<class 'tensorflow.python.framework.ops.Tensor'> 

それはテンソルと言います。すばらしいです!それは私にその内容に関する情報を与えてくれます。

は私が運転する期待したものと同様の実験をした:あなたが見ることができるよう、

W = tf.Variable(tf.truncated_normal([784, 10], mean=0.0, stddev=0.1)) 
b = tf.Variable(tf.constant(0.1, shape=[10])) 
Wx = tf.matmul(x, W) 
print Wx #Tensor("MatMul:0", shape=(?, 10), dtype=float32) 
print type(Wx) #<class 'tensorflow.python.framework.ops.Tensor'> 

しかし、テンソルの流れがWxのとCの両方が同じタイプであることを述べました。これは操作オブジェクトがないことを意味しますか、何か間違っていますか?

+0

いくつかの履歴については、「Tensorという用語を理解する方法」の回答を参照してください。http://stackoverflow.com/questions/37849322/how-to-understand-the-term-tensor-in-tensorflow/37870634#37870634 –

答えて

0

tf.Varibleはテンソルです。次に、演算に代入演算を行う値を代入します。または、tf.mul()を使用して操作することもできます。

+0

しかし、その型を印刷するときは操作ではありません。それが私の質問の中核です。 – Pinocchio

0

操作があります。グラフ内のすべての操作のリストは、graph.get_operations()(をtf.get_default_graph()またはsess.graphまたは状況に応じて得ることができます)で取得できます。

tf.mulのようなものは、乗算演算が生成するテンソルを返します(それ以降の操作では入力として使用するテンソルのすべてが厄介なものになります)。

0

私はエキスパートではありませんが、これで少しクリアされます。

 
x = tf.constant(1, shape=[10, 10]) 
y = tf.constant(1, shape=[10, 10]) 
z = tf.matmul(x, y, name='operation') 
# print(z) 
# tf.Tensor 'operation:0' shape=(10, 10) dtype=int32 
# z is a placeholder for the result of multiplication of x and y 
# but it has an operation attached to it 
# print(z.op) 
# tensorflow.python.framework.ops.Operation at 0x10bfe40f0 
# and so do x and y 
# print(x.op) 
# 
ses = tf.InteractiveSession() 
# now that we are in a session, we have an operation graph 
ses.graph.get_operation_by_name('operation') 
# tensorflow.python.framework.ops.Operation at 0x10bfe40f0 
# same operation that we saw attached to z 
ses.graph.get_operations() 
# shows a list of three operations, just as expected 
# this way you can define the graph first and then run all the operations in a session 
0

私はTensorFlowに非常に慣れていないんだけど、Wxtf.matmul(x, W)の出力のためのシンボリックハンドルである基本的な考え方のようです。実際に操作を作成したのですが、Wxにアクセスすると、結果が表示されます(セッションを実行するまで計算されていなくても)。

さらに詳しい説明はTensorFlow FAQをご覧ください。

0

tensorflowのコンテキストの外で、基本のPythonの中でこれを考えてみましょう。

どちらの場合も、あなたはintとなりますか?しかし、あなたは、この場合

type(f) 

をすれば、あなたはfunctionを取得します。テンソルフローと同じ:演算の結果の型は新しいテンソルですが、演算の型自体はテンソルではありません。

関連する問題