1. tf.Variable
tf.Variable.init(initial_value, trainable=True, collections=None, validate_shape=True, name=None)
| 参数名称 | 参数类型 | 参数含义 |
|---|---|---|
| initial_value | 所有可以转换为Tensor的类型 | 变量的初始值(必须给定的值) |
| trainable | bool | 如果为True,会把它加入到GraphKeys.TRAINABLE_VARIABLES,才能对它使用Optimizer |
| collections | list | 指定该图变量的类型、默认为[GraphKeys.GLOBAL_VARIABLES] |
| validate_shape | bool | 如果为False,则不进行类型和维度检查 |
| name | string | 变量的名称,如果没有指定则系统会自动分配一个唯一的值 |
assign函数:给图变量赋值
2. tf.get_variable
tf.get_variable(name, shape=None, dtype=None, initializer=None, regularizer=None, trainable=True, collections=None, caching_device=None, partitioner=None, validate_shape=True, custom_getter=None)
区别:
由于tf.Variable() 每次都在创建新对象,所有reuse=True 和它并没有什么关系。对于get_variable(),来说,如果已经创建的变量对象,就把那个对象返回,如果没有创建变量对象的话,就创建一个新的。
本文详细介绍了TensorFlow中tf.Variable和tf.get_variable的区别及用法。tf.Variable用于定义可训练的变量,而tf.get_variable提供了变量重用的功能。文章还讲解了两个函数的参数及其意义。
199

被折叠的 条评论
为什么被折叠?



