Python – tensorflow.IndexedSlices.op Attribute

Python – tensorflow.IndexedSlices.op Attribute

TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

op用于查找用于产生值作为输出的操作。它只在禁止急切执行的情况下起作用。

语法: tensorflow.IndexedSlices.op

返回:它返回产生数值的操作,作为输出。

例子1:在这个例子中,急切的执行被禁用。

# 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)

输出:


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" } } }

例子2:在这个例子中,急切的执行被启用,所以它将引发AttributeError。

# 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)

输出:


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.

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程