尽量使用tf.get_variable,当你想共享这个变量时,这样能够更容易重构代码。
tf.Variable所在的层次更低,更接近底层,有时候tf.get_variable不能使用时,tf.Variable仍然能够使用。
tf.Variable
__init__(
initial_value=None,
trainable=None,
collections=None,
validate_shape=True,
caching_device=None,
name=None,
variable_def=None,
dtype=None,
expected_shape=None,
import_scope=None,
constraint=None,
use_resource=None,
synchronization=tf.VariableSynchronization.AUTO,
aggregation=tf.VariableAggregation.NONE,
shape=None
)
tf.get_variable(
name,
shape=None,
dtype=None,
initializer=None, #可以是一个初始化的对象或者张量
regularizer=None,
trainable=None,
collections=None,
caching_device=None,
partitioner=None,
validate_shape=True,
use_resource=None,
custom_getter=None,
constraint=None,
synchronization=tf.VariableSynchronization.AUTO,
aggregation=tf.VariableAggregation.NONE
)