tf.trainable_variables和tf.all_variables的对比

https://blog.csdn.net/uestc_c2_403/article/details/72356448

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/xjp_xujiping/article/details/81627480