tensorflow, wie man Vorhersage

Möchte ich berechnen, Vorhersagen, verwenden Sie den folgenden code:

import tensorflow as tf

x = tf.placeholder("float", [None, n_input])
y = tf.placeholder("float", [None, n_classes])

pred = multilayer_perceptron(x, weights, biases)


cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(pred, y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)

# Initializing the variables

##trn.txt start

##tst.txt end
with tf.Session() as sess:
    sess.run(init)

    # Training cycle
    for epoch in range(training_epochs):
        avg_cost = 0.
        total_batch = int(num_lines_trn/batch_size)
        # Loop over all batches
        for i in range(total_batch):
            batch_x, batch_y = bat_x[i*batch_size:(i+1)*batch_size],bat_y[i*batch_size:(i+1)*batch_size]#mnist.train.next_batch(batch_size)
            # Run optimization op (backprop) and cost op (to get loss value)
            _, c = sess.run([optimizer, cost], feed_dict={x: batch_x,
                                                          y: batch_y})
            # Compute average loss
            avg_cost += c / total_batch

    correct_prediction = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))

    accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))

    print(sess.run(accuracy, feed_dict={x: tst_x, y: tst_y}))
    print(sess.run(accuracy, feed_dict={x: tst_x}))

Die Linie

print(sess.run(accuracy, feed_dict={x: tst_x, y: tst_y}))

zurück 0.80353 ist die Genauigkeit für die batch.

Jedoch möchte ich, um die Vorhersage Ergebnis. also fügte ich hinzu:

print(sess.run(accuracy, feed_dict={x: tst_x}))

Aber diese Zeile gibt einen Fehler zurück:

Müssen Sie füttern ein Wert für den Platzhalter tensor 'Placeholder_7' mit
"dtype" float

Wie kann ich dieses problem lösen?

InformationsquelleAutor | 2016-12-13
Schreibe einen Kommentar