1. 程式人生 > >TensorFlow報錯run() got multiple values for argument 'feed_dict'

TensorFlow報錯run() got multiple values for argument 'feed_dict'

這個報錯是因為sess.run(a,b,c)裡要執行的多個變數沒有用中括號括起來

舉個錯誤的例子:下面報錯是因為sess.run裡的c和d沒有用中括號

import tensorflow as tf

a = tf.placeholder(tf.float32, [1])
b = tf.placeholder(tf.float32, [1])
c = tf.multiply(a, b)
d = tf.add(a, b)

with tf.Session() as sess:
    prod, sum_ab = sess.run(c, d, feed_dict={a: [1.], b: [2.]})
    print(prod, sum_ab)

應該將後面那段程式改成:

import tensorflow as tf

a = tf.placeholder(tf.float32, [1])
b = tf.placeholder(tf.float32, [1])
c = tf.multiply(a, b)
d = tf.add(a, b)

with tf.Session() as sess:
    prod, sum_ab = sess.run([c, d], feed_dict={a: [1.], b: [2.]})
    print(prod, sum_ab)