當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python tensorflow.IndexedSlices.name屬性用法及代碼示例

TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。

名稱用於查找索引切片的名稱。這僅在禁用急切執行時有效。

用法:tensorflow.IndexedSlices.name

返回值:它返回IndexedSlices的名稱。

範例1:在此示例中,啟用了急切執行,因此將引發AttribbuteError。



Python3

# 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 name 
name = res.name 
  
# Printing the result 
print('Name:', name)

輸出:


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

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

AttributeError                            Traceback (most recent call last)

<ipython-input-7-f07b895be576> in <module>()
     12 
     13 # Finding name
---> 14 name = res.name
     15 
     16 # Printing the result

1 frames

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in name(self)
   1121   def name(self):
   1122     raise AttributeError(
-> 1123         "Tensor.name is meaningless when eager execution is enabled.")
   1124 
   1125   @property

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

範例2:在此示例中,急切執行被禁用。

Python3

# 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 name 
name = res.name 
  
# Printing the result 
print('Name:', name)

輸出:


data: Tensor("Const_13:0", shape=(2, 3), dtype=int32)
Name: Const_13:0




相關用法


注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.IndexedSlices.name Attribute。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。