1
Tensorflow를 처음 사용했습니다. 나는이 예를 통해 MNIST 훈련을했다.mnist 훈련 모델을 사용하여 이미지를 예측하는 방법
steps = 5000
with tf.Session() as sess:
sess.run(init)
for i in range(steps):
batch_x , batch_y = mnist.train.next_batch(50)
sess.run(train,feed_dict={x:batch_x,y_true:batch_y,hold_prob:0.5})
# PRINT OUT A MESSAGE EVERY 100 STEPS
if i%100 == 0:
print('Currently on step {}'.format(i))
print('Accuracy is:')
# Test the Train Model
matches = tf.equal(tf.argmax(y_pred,1),tf.argmax(y_true,1))
acc = tf.reduce_mean(tf.cast(matches,tf.float32))
print(sess.run(acc,feed_dict=
{x:mnist.test.images,y_true:mnist.test.labels,hold_prob:1.0}))
print('\n')
지금이 모델에 의한 예측을하고 싶다. 이 코드 줄을 사용하여 이미지를 열고 처리합니다.
feed_dict1 = {x: images}
classification = sess.run(y_pred, feed_dict1)
print (classification)
그것은이 오류를 반환
image = cv2.imread("Untitled.jpg")
image = np.multiply(image, 1.0/255.0)
images=tf.reshape(image,[-1,28,28,1])
I이 사용
.TypeError: The value of a feed cannot be a tf.Tensor object. Acceptable feed values include Python scalars, strings, lists, numpy ndarrays, or TensorHandles.
numpy 재구성을 사용해 보셨습니까? –
나는 그것을 시도했다. –
동일한 문제가 있는데 feed_dict는 입력 및 출력 값의 간단한 배열을 필요로한다는 것입니다. 그래서 내 1 차원 네트워크는 단지 당신이 그것을 먹이 동일한 값을 출력 : 'inputs = [[0], [0.5], [1]]' 'outputs = [[0], [0.5], [1]]' 'feed_dict = {inputType : inputs, outputType : outputs}' tf.reshape는 텐서를 반환합니다. –