目录
定义python op时使用的上下文管理器时的类。这个上下文管理器确认给定的值来自于同一个图,使该图成为默认图,并在该图插入name的作用域。例如,定义一个名为my_op的新python 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)1、__init____init__(
name,
default_name=None,
values=None
)参数:
name: 传递给op函数的名称参数。default_name: 如果name参数为None,则使用默认名称。values: The list of Tensor arguments that are passed to the op function.可能产生的异常:
TypeError: if default_name is passed in but not a string.启动scope块。
__enter__()返回值:
可能产生的异常:
ValueError: if neither name nor default_name is provided but values are.3、__exit____exit__(type_arg, value_arg, traceback_arg)