Tensorflow共享变量

    xiaoxiao2021-03-25  213

    tf.name_scope() vs tf.variable_scope()

    tf.name_scope creates namespace for operators in the default graphtf.variable_scope creates namespace for both variables and operators in defaul graph 3 tf.get_variable will ignore “name scope” but use “variable scope)

    for example :

    In [9]: with tf.name_scope("scope1"): ...: v1=tf.get_variable("var",[1],dtype=tf.float32) ...: v2=tf.Variable(1,name="var2",dtype=tf.float32) ...: a=tf.add(v1,v2) ...: In [10]: print(v1.name) var:0 In [11]: print(v2.name) scope1/var2:0 In [12]: print(a.name) scope1/Add:0 In [13]: with tf.variable_scope("scope2"): ...: v1=tf.get_variable("var",[1],dtype=tf.float32) ...: v2=tf.Variable(1,name="var2",dtype=tf.float32) ...: a=tf.add(v1,v2) ...: In [14]: print(v1.name) scope2/var:0 In [15]: print(v2.name) scope2/var2:0 In [16]: print(a.name) scope2/Add:0

    Use cases:

    tf.name_scope(name) for (name scope)tf.variable_scope(name_or_scope) for (variable scope )-tf.op_scope(values,name,default_name=None) for (name scope)

    tf.variable_op_scope(values,name_or_scope,Default_name=None) for (variable scope)

    -
    转载请注明原文地址: https://ju.6miu.com/read-4999.html

    最新回复(0)