tf.name_scope
Stay organized with collections
Save and categorize content based on your preferences.
A context manager for use when defining a Python op.
tf.name_scope(
name
)
This context manager pushes a name scope, which will make the name of all
operations added within it have a prefix.
For example, to define a new Python op called my_op
:
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)
When executed, the Tensors a
, b
, c
, will have names MyOp/a
, MyOp/b
,
and MyOp/c
.
If the scope name already exists, the name will be made unique by appending
_n
. For example, calling my_op
the second time will generate MyOp_1/a
,
etc.
Args |
name
|
The prefix to use on all names created within the name scope.
|
Raises |
ValueError
|
If name is None, or not a string.
|
Methods
__enter__
View source
__enter__()
Start the scope block.
Raises |
ValueError
|
if neither name nor default_name is provided
but values are.
|
__exit__
View source
__exit__(
type_arg, value_arg, traceback_arg
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.name_scope\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/name_scope) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/framework/ops.py#L6331-L6399) |\n\nA context manager for use when defining a Python op. \n\n tf.name_scope(\n name\n )\n\nThis context manager pushes a name scope, which will make the name of all\noperations added within it have a prefix.\n\nFor example, to define a new Python op called `my_op`: \n\n def my_op(a, b, c, name=None):\n with tf.name_scope(\"MyOp\") as scope:\n a = tf.convert_to_tensor(a, name=\"a\")\n b = tf.convert_to_tensor(b, name=\"b\")\n c = tf.convert_to_tensor(c, name=\"c\")\n # Define some computation that uses `a`, `b`, and `c`.\n return foo_op(..., name=scope)\n\nWhen executed, the Tensors `a`, `b`, `c`, will have names `MyOp/a`, `MyOp/b`,\nand `MyOp/c`.\n\nIf the scope name already exists, the name will be made unique by appending\n`_n`. For example, calling `my_op` the second time will generate `MyOp_1/a`,\netc.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|---------------------------------------------------------------|\n| `name` | The prefix to use on all names created within the name scope. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------------------|\n| `ValueError` | If name is None, or not a string. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|--------|---------------|\n| `name` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `__enter__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/framework/ops.py#L6375-L6394) \n\n __enter__()\n\nStart the scope block.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The scope name. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|--------------------------------------------------------------------|\n| `ValueError` | if neither `name` nor `default_name` is provided but `values` are. |\n\n\u003cbr /\u003e\n\n### `__exit__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/framework/ops.py#L6396-L6399) \n\n __exit__(\n type_arg, value_arg, traceback_arg\n )"]]