Below I have created a tf placeholder named "op testing":
self.center_words = tf.placeholder(tf.int32, shape=[self.batch_size], name='op testing')
print("Extracting the op", self.center_words.op)
When I print that self.center_words.op it prints out a structure like this:
op: "Placeholder"
attr {
key: "dtype"
value {
type: DT_INT32
}
}
attr {
key: "shape"
value {
shape {
dim {
size: 128
}
}
}
}
This works for any TensorFlow variable, function output, etc. What is this .op ?
TensorFlow Operations , also known as Ops , are nodes that perform computations on or with Tensor objects. After computation, they return zero or more tensors, which can be used by other Ops later in the graph. To create an Operation, you call its constructor in Python, which takes in whatever Tensor parameters needed for its calculation, known as inputs, as well as any additional information needed to properly create the Op, known as attributes . The Python constructor returns a handle to the Operation's output (zero or more Tensor objects), and it is this output which can be passed on to other Operations or Session.run
Short answer.
Ops are say the core of tensorflow
.
TensorFlow is a programming system in which you represent computations as graphs. Nodes in the graph are called ops (short for operations). An op takes zero or more Tensors, performs some computation, and produces zero or more Tensors.
self.center_words.op
in your example prints out the features of self.center_words
in that json-like format
Simply put, it prints the property of the particular tensor object . That is, it gives out details about
return type
dimension
and all possible information about the tensor object in question.
Minimal Example:
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
}
}
}
PS: Ignore the number( _11
) in ( zeros_11
) (that is in the value of the key name
). It is just a counter to track the runs. It keeps incrementing on every run within a session.
Source Implementation:
Code: tf.Tensor.op
Docs: tf.Tensor.op
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.