tensorflow中feed_dict{ }

1. placeholder

      tensorflowFor the time being no element in the assignment of a call, said placeholder. The so-called placeholder to placeholder, such as when required by assignment. Command is required tf.placeholder, the specific code:

1 import tensorflow as tf
2 a = tf.placeholder(tf.float32)

 Above represents a impart to a 32-bit floating-point number. How much concrete do not know, until the time of the assignment need to know.

 

2 。feed_dict

  feed_dictIt is used to assign the format of a typical word. For example, in the previous section on aassignments carried out. There feed_dict={a:8}. We assignment before and after a whole even look up:

 

1 >>> a = tf.placeholder(tf.float32)
2 >>> sess.run(a)
3 >>> b = tf.placeholder(tf.float32)
4 >>> multiply = tf.multiply(a,b)
5 >>> sess.run(multiply,feed_dict={a:8,b:2})
6 16.0
7 >>> sess.close()

A first for a supplement placeholder, when we sess.runtime error, we need to tell the assignment.

We define a variable multiplyfor a*b. When run by feed_dict assignment as a dictionary, to generate a product 16

 

Guess you like

Origin www.cnblogs.com/peterwong666/p/11141721.html