定義 Python 操作時使用的上下文管理器。
用法
tf.name_scope(
name
)參數
-
name用於在名稱範圍內創建的所有名稱的前綴。
拋出
-
ValueError如果名稱不是字符串。
屬性
-
name
這個上下文管理器推送一個名稱範圍,這將使添加在其中的所有操作的名稱都有一個前綴。
例如,要定義一個名為 my_op 的新 Python 操作:
def my_op(a, b, c, name=None):
with tf.name_scope("MyOp") as scope:
a = tf.convert_to_tensor(a, name="a")
b = tf.convert_to_tensor(b, name="b")
c = tf.convert_to_tensor(c, name="c")
# Define some computation that uses `a`, `b`, and `c`.
return foo_op(..., name=scope)
執行時,張量 a , b , c 將具有名稱 MyOp/a , MyOp/b 和 MyOp/c 。
在 tf.function 中,如果範圍名稱已存在,則通過附加 _n 使名稱唯一。例如,第二次調用 my_op 將生成 MyOp_1/a 等。
相關用法
- Python tf.nn.embedding_lookup_sparse用法及代碼示例
- Python tf.nest.is_nested用法及代碼示例
- Python tf.nn.RNNCellResidualWrapper.set_weights用法及代碼示例
- Python tf.nn.dropout用法及代碼示例
- Python tf.nest.assert_same_structure用法及代碼示例
- Python tf.nn.gelu用法及代碼示例
- Python tf.nn.RNNCellDeviceWrapper.set_weights用法及代碼示例
- Python tf.no_gradient用法及代碼示例
- Python tf.nn.embedding_lookup用法及代碼示例
- Python tf.numpy_function用法及代碼示例
- Python tf.nn.RNNCellDeviceWrapper.get_weights用法及代碼示例
- Python tf.nn.local_response_normalization用法及代碼示例
- Python tf.nn.scale_regularization_loss用法及代碼示例
- Python tf.nn.RNNCellResidualWrapper.add_loss用法及代碼示例
- Python tf.nn.max_pool用法及代碼示例
- Python tf.nn.RNNCellDropoutWrapper.set_weights用法及代碼示例
- Python tf.nest.map_structure用法及代碼示例
- Python tf.nn.l2_loss用法及代碼示例
- Python tf.nn.log_softmax用法及代碼示例
- Python tf.nn.weighted_cross_entropy_with_logits用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.name_scope。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
