다음 코드가 예외를 throw하는 이유는 무엇입니까? 나는 for
루프에서 feed_dict=
을 통해 자리를 공급,하지만 난 x
또는 y_tensor
의 값을 인쇄 할 때, 나는 다음과 같은 오류 메시지가 얻을 :tensorflow의 자리 표시 자 추적 : 'tensorflow.python.framework.errors_impl.InvalidArgumentError : 자리 표시 자 텐서에 값을 입력해야합니다.
'tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'input' with dtype float and shape [?,5]'.
놀랍게도, 나는 어떤 텐서 때의 오류가 발생하지 않습니다를 나는 다른 것을 인쇄한다. 예를 들어, y_tensor
만 인쇄 할 때, 내가 선언 한 행의 오류 메시지가 나타나지 않습니다. x
및 그 반대입니다. 문제를 테스트하기 위해서만 10
의 범위를 사용합니다. 주요 문제는이 조건에서 최적화가 작동하지 않는다는 것입니다. 이 문제를 어떻게 해결할 수 있습니까? 여기 강령
x = tf.placeholder(tf.float32, [None, 5], name='input')
W = tf.Variable(tf.zeros([5,1]))
b = tf.Variable(tf.zeros([1]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_tensor = tf.placeholder(tf.float32, [None, 1], name='output')
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_tensor * tf.log(y), reduction_indices=[1]))
optimizer = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
session = tf.Session()
init = tf.global_variables_initializer()
session.run(init)
for i in range(10):
batch_xs = [dataA[i], dataB[i], dataC[i], dataD[i],
dataE[i]]]
batch_ys = [[dataG[i]]]
session.run(optimizer ,feed_dict={x: batch_xs, y_tensor: batch_ys})
print(session.run(y))