Thursday, June 21, 2018

tensorflow useful functions

tf.add_n(): a list of tensors add
tf.assign(v,10): assign value 10 to a variable
#get variables function
tf.all_vaariables(): get all variables
tf.trainable_variables(): get all trainable variables
tf.concat(concat_dim, values, name='concat'): tf concatenation on the concat_dim dimension.
# get all collection variable keys
graph = tf.get_default_graph()
graph.get_all_collection_keys()
graph.get_tensor_by_name('mlp_b1:0') 

#get variable name
v.name

tf.train.batch(): 把数据分成一个一个的batch, 每个batch 中有batch_size 个数据
tf.name_scope() and tf.Variable_scope() 差不多,但是name_scope 对于tf.get_variable() 没影响。 这些都是用来方便管理的。可以在tensor board 可视化的时候更有帮助。

RNN中用的多的:
tf.clip_by_global_norm:用于控制梯度下降的参数。把梯度值控制在一个合理的范围内。