Sha*_*ana 6 python neural-network deep-learning tensorflow
self.center_words = tf.placeholder(tf.int32, shape=[self.batch_size], name='op testing')
print("Extracting the op",self.center_words.op)
Run Code Online (Sandbox Code Playgroud)
在上面我创建了一个名为"op testing"的tf占位符.当我打印self.center_words.op时,它打印出这样的结构
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_INT32
}
}
attr {
key: "shape"
value {
shape {
dim {
size: 128
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这适用于任何张量流变量,函数输出等.这是什么.op?
小智 9
TensorFlow Operations(也称为Ops)是在Tensor对象上或与Tensor对象执行计算的节点.在计算之后,它们返回零个或多个张量,这些张量可以在图形中的其他Ops中使用.要创建一个Operation,可以在Python中调用它的构造函数,它接受计算所需的任何Tensor参数,称为输入,以及正确创建Op所需的任何其他信息,称为属性.Python构造函数返回Operation的输出句柄(零个或多个Tensor对象),这个输出可以传递给其他Operations或Session.run
简单地说,它打印特定张量对象的属性。也就是说,它给出了关于
return type
dimension
以及有关张量对象的所有可能信息。
最小示例:
In [74]: with tf.Session() as sess:
...: zer = tf.zeros(shape=(32, 32))
...: print(zer.op)
...:
name: "zeros_11"
op: "Const"
attr {
key: "dtype"
value {
type: DT_FLOAT
}
}
attr {
key: "value"
value {
tensor {
dtype: DT_FLOAT
tensor_shape {
dim {
size: 32
}
dim {
size: 32
}
}
float_val: 0.0
}
}
}
Run Code Online (Sandbox Code Playgroud)
PS:忽略( _11
)中的number( ) zeros_11
(即key的值name
)。它只是一个跟踪运行的计数器。它在会话中的每次运行中不断增加。
源码实现:
代码:tf.Tensor.op
文档:tf.Tensor.op
归档时间: |
|
查看次数: |
9167 次 |
最近记录: |