tf.get_variable_scope().reuse_variables() 的使用

tf.name_scope()對tf.get_variable_scope().reuse_variables() 不起作用

# tf.get_variable_scope().reuse_variables() 的使用
import tensorflow as tf

with tf.variable_scope('a1'):
    print(tf.get_variable_scope().reuse)
    # with tf.name_scope('a2'):
    #     tf.get_variable_scope().reuse_variables()
    #     print(tf.get_variable_scope().reuse)
    with tf.variable_scope('a3'):
        tf.get_variable_scope().reuse_variables()
        print(tf.get_variable_scope().reuse)
    with tf.variable_scope('a4'):
        print(tf.get_variable_scope().reuse)

輸出

False
True
False

# tf.get_variable_scope().reuse_variables() 的使用
import tensorflow as tf

with tf.variable_scope('a1'):
    print(tf.get_variable_scope().reuse)
    with tf.name_scope('a2'):
        tf.get_variable_scope().reuse_variables()
        print(tf.get_variable_scope().reuse)
    with tf.variable_scope('a3'):
        tf.get_variable_scope().reuse_variables()
        print(tf.get_variable_scope().reuse)
    with tf.variable_scope('a4'):
        print(tf.get_variable_scope().reuse)

輸出

False
True
True
True
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章