Tensorflow get all variables in scope

Tensorflow get all variables in scope

Asked on December 19, 2018 in Tensorflow.
Add Comment


  • 2 Answer(s)

        To get all variables in a scope click here

        It need only the trainable variables to pass to an optimizer. It kept in a default collection, They are tf.GraphKeys.TRAINABLE_VARIABLES.

    Answered on December 19, 2018.
    Add Comment

    Here is an simple example to get it:

    import tensorflow as tf
     
    with tf.name_scope('some_scope1'):
        a = tf.Variable(1, 'a')
        b = tf.Variable(2, 'b')
        c = tf.Variable(3, 'c')
     
    with tf.name_scope('some_scope2'):
        d = tf.Variable(4, 'd')
        e = tf.Variable(5, 'e')
        f = tf.Variable(6, 'f')
     
    h = tf.Variable(8, 'h')
     
    for i in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='some_scope'):
        print i   # i.name if you want just a name
    
    Answered on December 19, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.