Deep learning和tensorflow学习记录(三):tf.name_scope

定义于:tensorflow/python/framework/ops.py

定义Python操作时使用的上下文管理器。

此上下文管理器验证给定values的来自同一个图,使该图成为默认图,并在该图中推送名称范围。

方法:

__init__(

name,

default_name=None,

values=None

)

初始化上下文管理器。

name: 传递给op函数的name参数。

default_name: name参数为的默认名称name

values: Tensor传递给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)

猜你喜欢

转载自blog.csdn.net/heiheiya/article/details/80943234