tf.name_scope

Class name_scope

Aliases:

  • Class tf.keras.backend.name_scope
  • Class tf.name_scope

Defined in tensorflow/python/framework/ops.py.

See the guide: Building Graphs > Utility functions

A context manager for use when defining a Python op.

This context manager validates that the given values are from the same graph, makes that graph the default graph, and pushes a name scope in that graph (see tf.Graph.name_scope for more details on that).

For example, to define a new Python op called my_op:

def my_op(a, b, c, name=None):
  with tf.name_scope(name, "MyOp", [a, b, c]) 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)

Properties

name

Methods

__init__

__init__(
    name,
    default_name=None,
    values=None
)

Initialize the context manager.

Args:

  • name: The name argument that is passed to the op function.
  • default_name: The default name to use if the name argument is None.
  • values: The list of Tensor arguments that are passed to the op function.

__enter__

__enter__()

Start the scope block.

Returns:

The scope name.

Raises:

  • ValueError: if neither name nor default_name is provided but values are.

__exit__

__exit__(
    type_arg,
    value_arg,
    traceback_arg
)