Tensorflow中的Fetch与Feed操作
发布时间
阅读量:
阅读量
一、Fetch操作
在Tensorflow框架中,Fetch操作的定义涉及会话的建立以及对运算操作的调用。当需要执行多个运算操作时,可以通过将这些op整合为数组或列表的形式,将其传递至sess.run()函数中,从而实现对多个运算操作的同时执行,并获取相应的输出结果。
实例展示
设定若干固定参数及操作符
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)
全部评论 (0)
还没有任何评论哟~
