What is the difference between tf.placeholder and tf.Variable ?

What is the difference between tf.placeholder and tf.Variable ?

Asked on November 17, 2018 in Tensorflow.
Add Comment


  • 3 Answer(s)

        Simply,  You utilize tf.Variable for trainable variables. for example, weights (W) and biases (B) for your model.

    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')
    

    To feed actual training tf.placeholder is used.

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

    This is the manner by which 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)
    
    Answered on November 17, 2018.
    Add Comment

    The difference between tf.placeholder and tf.Variable are,

    • With tf.Variable you need to give an initial value when you declare it.
    • With tf.placeholder you don’t need to give an initial value and you can determine it at run time with the feed_dict argument inside Session.run.
    Answered on November 17, 2018.
    Add Comment

        The tf.Variables are stateful nodes which output their current value. In TensorFlow we must have to assign values to a variable.

    Variables(tf.varibales(SomeValue)):
    

        The tf.placeholder are nodes whose value is fed in at execution time. Such as, inputs, labels.

    Placeholders(tf.placeholders(dtype, shape)):
    
    Answered on November 17, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.