(4) fetch and feed

1.fetch is to use sess.run () to run multiple 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 placeholder

Is the beginning of the operation when there is no specific definition of value, and then pass the value of real-time operations running when traditional values ​​in the form of a dictionary. (Corresponding to the transfer function parameters)

import tensorflow as tf
#创建32浮点型占位符,即下面的input此时没有具体的值
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]

Published 65 original articles · won praise 3 · Views 1682

Guess you like

Origin blog.csdn.net/qq_34405401/article/details/104334650