Operation 与 Tensor

Tensor代表操作的输出结果 ,Operation表示一个操作,

 c = tf.matmul(a, b)

c是Tensor对象,还是Operation对象?

这里c应该是Tensor对象。

有些操作没有返回值,此时该对象就是一个Operation对象。如

optimizer = tf.train.AdamOptimizer(LEARNING_RATE).minimize(self.loss)

 optimizer是一个Operation对象,因为minimize函数没有输出值。

附api:

  • Class Operation

Defined in tensorflow/python/framework/ops.py.

Represents a graph node that performs computation on tensors.

An Operation is a node in a TensorFlow Graph that takes zero or more Tensor objects as input, and produces zero or more Tensor objects as output. Objects of type Operation are created by calling a Python op constructor (such as tf.matmul) or tf.Graph.create_op.

For example c = tf.matmul(a, b) creates an Operation of type "MatMul" that takes tensors a and b as input, and produces c as output.

After the graph has been launched in a session, an Operation can be executed by passing it to tf.Session.run. op.run() is a shortcut for calling tf.get_default_session().run(op).

Operation

表示图中的节点,实现对Tensor的计算。

一个Operation对象是Tensorflow计算图中的一个节点,接收0或多个Tensor对象作输入,输出0或多个Tensor对象。

  • Class Tensor

Defined in tensorflow/python/framework/ops.py.

Represents one of the outputs of an Operation..

Operation可以有多个输出,Tensor表示Operation输出中的一个。

A Tensor is a symbolic handle to one of the outputs of an Operation. It does not hold the values of that operation's output, but instead provides a means of computing those values in a TensorFlow tf.Session.

This class has two primary purposes:

  1. A Tensor can be passed as an input to another Operation. This builds a dataflow connection between operations, which enables TensorFlow to execute an entire Graph that represents a large, multi-step computation.

  2. After the graph has been launched in a session, the value of the Tensor can be computed by passing it to tf.Session.run. t.eval() is a shortcut for calling tf.get_default_session().run(t).

In the following example, c, d, and e are symbolic Tensor objects, whereas result is a numpy array that stores a concrete value:

c = tf.constant([[1.0, 2.0], [3.0, 4.0]])
d = tf.constant([[1.0, 1.0], [0.0, 1.0]])
e = tf.matmul(c, d)

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值