您的位置:首页 > 其它

TF中的tf.Variable 和 tf.placehold 的区别

2017-07-16 13:30 148 查看
参考自: https://stackoverflow.com/questions/36693740/whats-the-difference-between-tf-placeholder-and-tf-variable

tf.placehold 占位符。 主要为真实输入数据和输出标签的输入, 用于在 feed_dict中的变量,不需要指定初始值,具体值在feed_dict中的变量给出。

images_placeholder = tf.placeholder(tf.float32, shape=(batch_size, IMAGE_PIXELS))
labels_placeholder = tf.placeholder(tf.int32, shape=(batch_size))

#This is how you feed the training examples during the training:

for step in xrange(FLAGS.max_steps):
feed_dict = {
images_placeholder: images_feed,
labels_placeholder: labels_feed,
}
_, loss_value = sess.run([train_op, loss], feed_dict=feed_dict)


tf.Variable 主要用于定义weights bias等可训练会改变的变量,必须指定初始值。

weights = tf.Variable(
tf.truncated_normal([IMAGE_PIXELS, hidden1_units],
stddev=1.0 / math.sqrt(float(IMAGE_PIXELS))), name='weights')

biases = tf.Variable(tf.zeros([hidden1_units]), name='biases')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Variable placehold