tf.name_scope与tf.variable_scope

参考文章:https://blog.csdn.net/Jerr__y/article/details/70809528
参考文章:https://blog.csdn.net/u012436149/article/details/53696970

tf.trainable_variables返回的是需要训练的变量列表

tf.all_variables返回的是所有变量的列表

例如:

import tensorflow as tf;  
import numpy as np;  
import matplotlib.pyplot as plt;  

v = tf.Variable(tf.constant(0.0, shape=[1], dtype=tf.float32), name='v')
v1 = tf.Variable(tf.constant(5, shape=[1], dtype=tf.float32), name='v1')

global_step = tf.Variable(tf.constant(5, shape=[1], dtype=tf.float32), name='global_step', trainable=False)
ema = tf.train.ExponentialMovingAverage(0.99, global_step)

for ele1 in tf.trainable_variables():
	print ele1.name
for ele2 in tf.all_variables():
	print ele2.name

输出:

v:0
v1:0


v:0
v1:0
global_step:0

分析:

上面得到两个变量,后面的一个得到上三个变量,因为global_step在声明的时候说明不是训练变量,用来关键字trainable=False。

猜你喜欢

转载自blog.csdn.net/u014106566/article/details/84308120