版权声明:本文为博主原创文章,转载请附上博文链接! https://blog.csdn.net/weixin_38314865/article/details/84716152
使用feed_dict一般会伴有占位符,如
x = tf.placeholder(tf.float32)
但是没有tf.placeholder也可以使用feed_dict方法,如下面这个例子:
import tensorflow as tf
input1 = tf.constant([2], dtype=tf.float32)
input2 = tf.constant([3], dtype=tf.float32)
output = tf.multiply(input1, input2)
with tf.Session() as sess:
print(sess.run(output)) # 输出6.
print(sess.run(output, feed_dict={input1: [3.]})) # 输出9.
但是要注意的是feed_dict中变量的维度要与该变量的原维度一致,在上面的例子中,feed_dict中input1的维度也必须只有1