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?
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
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
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
}
}
}
P.S.: 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With