标签:class code tps ble detail session val ted bottom
二者的主要区别在于:
tf.Variable:主要在于一些可训练变量(trainable variables),比如模型的权重(weights,W)或者偏执值(bias);
weights = tf.Variable( tf.truncated_normal([IMAGE_PIXELS, hidden1_units], stddev=1./math.sqrt(float(IMAGE_PIXELS)), name=‘weights‘) ) biases = tf.Variable(tf.zeros([hidden1_units]), name=‘biases‘)
tf.placeholder:用于得到传递进来的真实的训练样本:
images_placeholder = tf.placeholder(tf.float32, shape=[batch_size, IMAGE_PIXELS])
labels_placeholder = tf.placeholder(tf.int32, shape=[batch_size])
如下则是二者真实的使用场景:
for step in range(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 的值将会改变,也即被修改,这也是其名称的来源(variable,变量)。
What’s the difference between tf.placeholder and tf.Variable
TensorFlow 辨异 —— tf.placeholder 与 tf.Variable
标签:class code tps ble detail session val ted bottom
原文地址:https://www.cnblogs.com/Ph-one/p/9078821.html