What is the "op" tensor?

self.center_words = tf.placeholder(tf.int32, shape=[self.batch_size], name='op testing')
print("Extracting the op",self.center_words.op)

      

In the example above, I created a placeholder tap called "op testing". And when I print this self.center_words.op it prints some kind of 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 ?

+3


source to share


3 answers


TensorFlow Operations, also known as Ops, are nodes that perform computations on or with Tensor objects. Once calculated, 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 accepts any Tensor parameters needed to calculate it, known as inputs, as well as any additional information needed to create an Op correctly, known as attributes. The Python constructor returns a handle to the Output of operations (zero or more tensor objects), and it is this output that can be piped to other operations or Session.run



+2


source


Short answer.

Ops talk about the core tensorflow

.



TensorFlow is a programming system where you represent computations as graphs. The nodes in the graph are called operations (short for operations). The operator takes zero or more tensors, performs some calculations, and produces zero or more tensors.

self.center_words.op

in your example prints out functions self.center_words

in this json-like format

+4


source


In simple terms, it prints a property of a specific tensor object. That is, it provides information about

  • which operation is responsible for generating the tensor
  • what is this return type

  • what is this dimension

and all possible information about the considered tensor object.

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 number ( _11

) in ( zeros_11

) (that is, in key value name

). This is just a counter to keep track of runs. It keeps increasing every time you start a session.


Source implementation:

Code: tf.Tensor.op
Docs: tf.Tensor.op

+3


source







All Articles