<规约计算>
具有降维功能,所有reduce_xxx系列操作中,都在降维
axis的默认值为None,即把input_tensor降为一个数
对于二维的input_tensor而言,axis=0,按列计算
axis=1, 按行计算
tf.reduce_mean:求平均值
<共享变量>(一个模型需要使用其他模型创建的变量,两个模型一起训练)
get_variable方法,variable_scope方法(变量作用域)
tf.get_variable(<name>, <shape>, <initializer>)
使用get_variable创建两个同样名字的变量不可行,可使用variable_scope分隔开
with tf.variable_scope("test1"):
var1 = tf.get_variable("firstvar", shape=[1], dtype=tf.float32)
with tf.variable_scope("test2"):
var2 = tf.get_variable("firstvar", shape=[1], dtype=tf.float32)
使用作用域中的reuse来实现共享变量功能
令reuse=True,表示使用已经定义过的变量
with tf.variable_scope("test1",reuse=True):
var3 = tf.get_variable("firstvar", shape=[1], dtype=tf.float32)
with tf.variable_scope("test2",reuse=True):
var4 = tf.get_variable("firstvar", shape=[1], dtype=tf.float32)
使用withvariable_scope(“name”) as XXX的方式定义作用域时,所定义的作用域变量XXXX不受外围scope的限制
with tf.variable_scope("scope1") as sp:
var1 = tf.get_variable("v",[1])
with tf.variable_scope("scope2"):
var2=tf.get_variable("v",[1])
with tf.variable_scope(sp) as sp1:
var3=tf.get_variable("v3",[1])