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')
今このモデルで予測したいです。これらのコード行で画像を開いて処理します。
image = cv2.imread("Untitled.jpg")
image = np.multiply(image, 1.0/255.0)
images=tf.reshape(image,[-1,28,28,1])
私はこれを使用します。
feed_dict1 = {x: images}
classification = sess.run(y_pred, feed_dict1)
print (classification)
それはこのエラーを返します。
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はテンソルを返します –