1.fetch 就是用sess.run()同时运行多个op
import tensorflow as tf
v1=tf.constant(3)
v2=tf.constant(4)
v3=tf.constant(5)
ad=tf.add(v2,v2)
mul=tf.multiply(v1,ad)
with tf.Session() as sess:res=sess.run([mul,ad])print(res)
[24, 8]
2.feed 占位符
就是刚开始定义操作时候没有具体的值,在运行操作时候再实时把值传入,传值采用字典的形式。(相当于函数传参 或 c++的变量cin)
import tensorflow as tf
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:3.4,input2:6.0}))
20.400002