Python – tensorflow.IndexedSlices.op Attribute

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks.

op is used to find the operation used to that produces value as an output. It only works when eager execution is disabled.

Syntax: tensorflow.IndexedSlices.op

Returns: It returns the operation that produces values as an output.

Example 1: In this example eager execution is disabled.



Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the library
import tensorflow as tf
  
# Disable Eager execution
tf.compat.v1.disable_eager_execution()
  
# Initializing the input
data = tf.constant([[1, 2, 3], [4, 5, 6]])
  
# Printing the input
print('data: ', data)
  
# Calculating result
res = tf.IndexedSlices(data, [0], 1)
  
# Finding operation
op = res.op
  
# Printing the result
print('Operation: ', op)

chevron_right


Output:


data:  Tensor("Const:0", shape=(2, 3), dtype=int32)
Operation:  name: "Const"
op: "Const"
attr {
  key: "dtype"
  value {
    type: DT_INT32
  }
}
attr {
  key: "value"
  value {
    tensor {
      dtype: DT_INT32
      tensor_shape {
        dim {
          size: 2
        }
        dim {
          size: 3
        }
      }
      tensor_content: "\001\000\000\000\002\000\000\000\003\000\000\000\004\000\000\000\005\000\000\000\006\000\000\000"
    }
  }
}

Example 2: In this example eager execution is enable so it will raise AttributeError.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the library
import tensorflow as tf
  
# Initializing the input
data = tf.constant([[1, 2, 3], [4, 5, 6]])
  
# Printing the input
print('data: ', data)
  
# Calculating result
res = tf.IndexedSlices(data, [0], 1)
  
# Finding operation
op = res.op
  
# Printing the result
print('Operation: ', op)

chevron_right


Output:


data:  tf.Tensor(
[[1 2 3]
 [4 5 6]], shape=(2, 3), dtype=int32)

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-1-8dd32836815c> in <module>()
     12 
     13 # Finding operation
---> 14 op = res.op
     15 
     16 # Printing the result

1 frames

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in op(self)
   1111   def op(self):
   1112     raise AttributeError(
-> 1113         "Tensor.op is meaningless when eager execution is enabled.")
   1114 
   1115   @property

AttributeError: Tensor.op is meaningless when eager execution is enabled.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.