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

时间:2022-07-24
本文章向大家介绍tf.get_variable_scope().reuse_variables() 的使用,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

交流、咨询,有疑问欢迎添加QQ 2125364717,一起交流、一起发现问题、一起进步啊,哈哈哈哈哈

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

各位看官老爷,如果觉得对您有用麻烦赏个子,创作不易,0.1元就行了。下面是微信乞讨码:

添加描述

添加描述