2017-01-29 4 views
0

Ich befolge das TensorFlow MNIST for Experts-Tutorial, aber ich weiß nicht, wie man das trainierte Netzwerk dazu bringt, einen neuen Datensatz vorherzusagen.Vorhersage mit TensorFlow MNIST für Experten

Unten ist mein Code: Ich habe alle Zeilen in TensorFlow MNIST for Experts tutorial und ich importierte eine csv-Datei mit Pandas als Dataframe testt.

y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) 
feed_dict = {x: testt[0], keep_prob:1.0} 
classification = y_conv.eval(y, feed_dict) 
print(classification) 

Ich erhalte diesen Fehler

AttributeError       Traceback (most recent call last) 
<ipython-input-36-96dfe9b26149> in <module>() 
     2 y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) 
     3 feed_dict = {x: testt[0], keep_prob:1.0} 
----> 4 classification = y_conv.eval(y, feed_dict) 
     5 print(classification) 

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in eval(self, feed_dict, session) 
    573 
    574  """ 
--> 575  return _eval_using_default_session(self, feed_dict, self.graph, session) 
    576 
    577 

C:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in _eval_using_default_session(tensors, feed_dict, graph, session) 
    3627      "`eval(session=sess)`.") 
    3628 else: 
-> 3629  if session.graph is not graph: 
    3630  raise ValueError("Cannot use the given session to evaluate tensor: " 
    3631      "the tensor's graph is different from the session's " 

AttributeError: 'dict' object has no attribute 'graph' 

Bitte helfen. Ich bin mir nicht sicher, wie ich das trainierte Netzwerk richtig anrufe.

Antwort

1

Sie müssen nur die Ausgabe von y mit einem sess.run Anruf nach dem Training Schleife erhalten:

with tf.Session() as sess: 
    for i in range(1000): 
     batch = mnist.train.next_batch(100) 
     train_step.run(feed_dict={x: batch[0], y_: batch[1]}) 

    logits = sess.run(y, feed_dict={x: test_data}) 
    pred = tf.nn.softmax(logits) 
    print(pred) # or print(tf.argmax(pred, dimension=1)) for the index 
+0

Danke, das ist wirklich hilfreich ist. – Shadowninjazx

+0

Kein Problem, Sie können jeden Wert in der Grafik wie folgt abrufen. Gewichte, Verlust usw. – Nitro