tf.placeholder和tf.Variable的区别

tf.Variable(self,
initial_value: Any = None,
trainable: Any = None,
collections: Any = None,
validate_shape: bool = True,
caching_device: Any = None,
name: Any = None,
variable_def: Any = None,
dtype: Any = None,
expected_shape: Any = None,
import_scope: Any = None,
constraint: Any = None,
use_resource: Any = None,
synchronization: VariableSynchronization = VariableSynchronization.AUTO,
aggregation: VariableAggregation = VariableAggregation.NONE,
shape: Any = None)
用来初始化一个变量,可以构造一个任意类型任意形状的tensor,构造之后,可以通过tf.rehshpe修改形状,tf.cast修改变量类型以及tf.assgn等方法赋值。tf.placeholder和tf.Variable的区别
生成的结果如下:
tf.placeholder和tf.Variable的区别

使用tf.Variable()类型构造的数据必须使用tf.global_variables_initializer()初始化。
tf.placeholder(dtype: Any,
shape: Any = None,
name: Any = None)用于得到传递进来的真实的训练样本。tf.placeholder和tf.Variable的区别
最后生成的结果如下
tf.placeholder和tf.Variable的区别