本文主要是介绍【tensorflow】学习记录一: tf.global_variables_initializer(),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
tensorflow中初始化参数使用:sess.run(tf.global_variables_initializer()),意思是初始化全局所有变量。
源代码:
def global_variables_initializer():"""Returns an Op that initializes global variables.Returns:An Op that initializes global variables in the graph."""return variables_initializer(global_variables())def global_variables():"""Returns global variables.Returns:A list of `Variable` objects."""return ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)def variables_initializer(var_list, name="init"):"""Returns an Op that initializes a list of variables.Args:var_list: List of `Variable` objects to initialize.name: Optional name for the returned operation.Returns:An Op that run the initializers of all the specified variables."""if var_list:return control_flow_ops.group(*[v.initializer for v in var_list], name=name)return control_flow_ops.no_op(name=name)
class Variable(object):def _init_from_args(self, ...):self._initializer_op = state_ops.assign(self._variable, self._initial_value,validate_shape=validate_shape).op@propertydef initializer(self):"""The initializer operation for this variable."""return self._initializer_op
调用tf.global_variables_initializer()后,返回variables_initializer(global_variables())
global_variables()调用后会返回全局的变量的list。
variables_initializer(var_list,name="init")对参数var_list中的所有元素进行initializer。
这篇关于【tensorflow】学习记录一: tf.global_variables_initializer()的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!