TensorFlow中variable与placeholder区别

#placeholder是一个容器,需要以字典的形式赋值;

import tensorflow as tf

#placeholder是一个容器,需要赋值(以字典的形式)
input1 = tf.placeholder(tf.float32)
input2 = tf.placeholder(tf.float32)

output = tf.multiply(input1,input2)

with tf.Session() as sess:
    print(sess.run(output,feed_dict={input1:[7.],input2:[2.]}))
import tensorflow as tf

state = tf.Variable(0, name = 'counter')
one = tf.constant(1)

new_value = tf.add(state, one)      #相加    1
update = tf.assign(state, new_value)#把new_value的值赋给state 2
init = tf.initialize_all_variables() #must have if define variable

with tf.Session() as sess:
    sess.run(init)
    for _ in range(3):
        sess.run(update)      #执行1,2两步
        print(sess.run(state)) 


猜你喜欢

转载自blog.csdn.net/sinat_18558057/article/details/88586478