zoukankan      html  css  js  c++  java
  • 吴裕雄 python 神经网络——TensorFlow 变量管理

    import tensorflow as tf
    
    with tf.variable_scope("foo"):
        v = tf.get_variable("v", [1], initializer=tf.constant_initializer(1.0))
                            
    #with tf.variable_scope("foo"):
       # v = tf.get_variable("v", [1])
        
    with tf.variable_scope("foo", reuse=True):
        v1 = tf.get_variable("v", [1])
    print(v == v1)
    
    #with tf.variable_scope("bar", reuse=True):
       # v = tf.get_variable("v", [1])

    with tf.variable_scope("root"):
        print(tf.get_variable_scope().reuse)
        
        with tf.variable_scope("foo", reuse=True):
            print(tf.get_variable_scope().reuse)
            
            with tf.variable_scope("bar"):
                print(tf.get_variable_scope().reuse)
                
        print(tf.get_variable_scope().reuse)

    v1 = tf.get_variable("v", [1])
    print(v1.name)
    
    with tf.variable_scope("foo",reuse=True):
        v2 = tf.get_variable("v", [1])
    print(v2.name)
    
    with tf.variable_scope("foo"):
        with tf.variable_scope("bar"):
            v3 = tf.get_variable("v", [1])
            print(v3.name)
            
    v4 = tf.get_variable("v1", [1])
    print(v4.name)

    with tf.variable_scope("",reuse=True):
        v5 = tf.get_variable("foo/bar/v", [1])
        print(v5 == v3)
        v6 = tf.get_variable("v1", [1])     
        print(v6 == v4)

  • 相关阅读:
    7. v-bind 绑定Class操作 【对象语法】
    7。 V-bind 绑定
    【离散化】
    【洛谷 1576】最小花费
    【洛谷 1078】文化之旅
    【POJ 2115】CLooooops
    【洛谷 1516】青蛙的约会
    【UOJ 270】电厂计划
    【UOJ 92】有向图的强联通分量
    【POJ 2186】Popular Cows
  • 原文地址:https://www.cnblogs.com/tszr/p/10875049.html
Copyright © 2011-2022 走看看