一、Fetch操作
Tensorflow中的Fetch操作是指:定义会话,调用op实现相应功能时,Fetch操作可以sess.run()多个op(同时run多个op),将多个op组成数组(或者说列表),传入run中可以得到多个op的输出结果。
实例展示
- 定义一些常量和op
import tensorflow as tf
#Fetch的作用:会话里执行多个op,得到它运行后的结果
input1 = tf.constant(3.0)
input2 = tf.constant(2.0)
input3 = tf.constant(5.0)
add = tf.add(input2,input3)
mul = tf.multiply(input1, add)
- 实现Fetch操作
with tf.Session() as sess:
#会话中执行多个op,这里的op是mul和add
result = sess.run([mul,add])
print(result)
- 结果