Created
October 4, 2017 08:28
-
-
Save InnerPeace-Wu/837164549a98bdc202f457260af056fa to your computer and use it in GitHub Desktop.
get variables in tensorflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
def get_v_names(): | |
tf.reset_default_graph() | |
with tf.variable_scope('test'): | |
a = tf.Variable(tf.ones([2]),tf.float32, name='a') | |
b = tf.Variable(tf.zeros([3]), dtype=tf.float32, name='b',trainable=False) | |
# GLOBAL_VARIABLES: get all variable, e.g. a & b | |
# GLOBAL_TRAINABLE: get trainable variable, e.g. a | |
for i in tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES):#TRAINABLE | |
print(i.name) # i.name if you want just a name | |
# another way to get trainable variables | |
for i in tf.trainable_variables(): | |
print(i.name) | |
if __name__ == '__main__': | |
get_v_names() | |
'''out: | |
test/a:0 | |
test/b:0 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment