So testen Sie ein Modell in tensor-flow?

Ich bin nach diesem tutorial:

https://www.tensorflow.org/versions/r0.9/tutorials/mnist/beginners/index.html#mnist-for-ml-beginners

Was ich im Stande sein will zu tun ist, übergeben Sie in einem test-Bild x - als ein numpy-array, und sehen Sie die daraus resultierenden softmax-Klassifikation Werte - vielleicht als eine weitere numpy-array. Alles, was ich online finden kann zum testen mit tensor-flow-Modellen arbeitet, indem in test-Werte und test-Etiketten und die Ausgabe der Genauigkeit. In meinem Fall möchte ich die Ausgabe der Modell-Beschriftungen direkt auf der Basis der test-Werte.

Dies ist, was ich versuche:
import tensorflow als tf
import numpy as np
von skimage import Farbe,io

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)

x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)

for i in range(1000):
  batch_xs, batch_ys = mnist.train.next_batch(100)
  sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

#so now its trained successfully, and W and b should be the stored "model" 

#now to load in a test image

greyscale_test = color.rgb2gray(io.imread('4.jpeg'))
greyscale_expanded = np.expand_dims(greyscale_test,axis=0)    #now shape (1,28,28)
x = np.reshape(greyscale_expanded,(1,784))     #now same dimensions as mnist.train.images

#initialize the variable
init_op = tf.initialize_all_variables()

#run the graph
with tf.Session() as sess:
    sess.run(init_op) #execute init_op
    print (sess.run(feed_dict={x:x}))    #this is pretty much just a shot in the dark. What would go here?

Es jetzt Ergebnisse, in:

TypeError                                 Traceback (most recent call last)
<ipython-input-116-f232a17507fb> in <module>()
     36     sess.run(init_op) #execute init_op
---> 37     print (sess.run(feed_dict={x:x}))    #this is pretty much just a shot in the dark. What would go here?

TypeError: unhashable type: 'numpy.ndarray'

So, wenn die Ausbildung, die sess.laufen ist bestanden train_step und ein feed_dict. Wenn ich versuche zu bewerten, ein tensor x, würde das gehen, in der feed-dict? Würde ich auch verwenden, sess.laufen?(scheinbar habe ich zu), aber was wäre die train_step werden? Gibt es eine "test_step" oder "evaluate_step"?

InformationsquelleAutor BigBoy1337 | 2016-06-29
Schreibe einen Kommentar