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

来源:互联网 发布:淘宝女装代理排除同款 编辑:程序博客网 时间:2024/05/16 12:39

参考自: 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')
原创粉丝点击