tf.Varibale tf.placeholder tf.global_variables() tf.trainable_variales()

比我的写的好多了,极力推荐

tf.placeholder

	tf.placeholder
		tf.placeholder(
		    dtype,
		    shape=None,
		    name=None
		)

参数

dtype是必须的
shape可以没有 如果缺省则表示 可以接受符合类型的任意shape数据(这点要多注意,有时候会很方面,因为tensorlfow好多op 支持broadcast操作)

tf.Varibale

  __init__(
    initial_value=None,
    trainable=True,
    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
)

这个没什么讲的 这里引申一下讲两个方法:

tf.global_variables()用来获取构造的图中所包含的所有的变量
tf.trainable_variales() 用来获取构造的图中所包含的所有的需要训练的变量
看了一下 有的博客说需要初始化才能使用(亲自测试了一下,是错误的),不过如果你要打印变量的值需要先进行初始化

以上所有的知识点 都在下面的这段代码中体现(代码出处.)

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_32806793/article/details/82988695
今日推荐