Attributes of tensorflow operations

Consider the following example:


It will produce the following graph:

We can see a constant tensorflow operation has two attributes: dtype is the type of the elements stored in the tensor; value is the tensor. The value is a python dict with the single key:”tensor”. The value of “tensor” is another python dict with the keys: “dtype”, “tensor_shape”, and “tensor_content”. The “dtype” is the data type of the elements in the data.  “tensor_shape” describes the shape of the data, again it is a python dict with only one key “dim”. The “dim” is a list of dicts. Every dict in the list has single key “size” that is the size of a dimension of the data. For a scalar constant, the “tensor_shape” is an empty dict. The “tensor_content” is the data itself which is represented by octet strings. Every number in the data is represented by 4 octet strings.  For scalar constants, it uses a key like “int_val” instead of “tensor_content” to store the content of the data.

For operations that do not store data, there would be no dtype and value attributes. Instead, they may have a T attribute to indicate the data type of its output.


If you like my content, please consider buying me a coffee. Buy me a coffeeBuy me a coffee Thank you for your support!

Leave a Reply