2017-01-10 10 views
0

ごと! シャッフルから画像とラベルを取得したので、convの画像はうまく機能します。 tfreocordsテンソルフローのシャッフルのラベルが機能しないのはなぜですか?

... 
train_images, train_labels = shuffle(train_all_images, train_all_labels) 
... 

しかし、以下のようtrain_labels動作しませんから

画像とラベル:それがすべてでtrain_labelsから値を取得することはできませんので

numpy.sum(numpy.argmax(predictions, 1) == train_labels) 

結果は、常に間違っています。

いくつかの詳細は以下のとおりです。

train_all_images, train_all_labels = read_and_decode("train") 

train_images, train_labels = shuffle(train_all_images, train_all_labels) 

......いくつかのトレーニングモデル

optimizer = tf.train.MomentumOptimizer(learning_rate, 
             0.9).minimize(loss, 
                global_step=batch) 
train_prediction = tf.nn.softmax(logits) 

with tf.Session() as sess: 
    tf.global_variables_initializer().run() 
    tf.train.start_queue_runners(sess) 
    print('Initialized!') 

    for step in xrange(int(num_epochs * train_size) // BATCH_SIZE): 
     sess.run(optimizer) 
     if step % EVAL_FREQUENCY == 0:    
      l, lr, predictions = sess.run([loss, learning_rate, train_prediction]) 

      print('Minibatch loss: %.3f, learning rate: %.6f' % (l, lr)) 
      print('Minibatch error: %.1f%%' % error_rate(predictions, train_labels)) 
      sys.stdout.flush() 

def error_rate(predictions, labels): 
    return 100.0 - (100.0 * 
    numpy.sum(numpy.argmax(predictions, 1) == labels)/
    predictions.shape[0]) 
+0

動作しないコードの完全な再現可能な例を含めることはできますか? 2つの行から、何が起こっているのかははっきりしません(例えば、 'sess.run()'があなたが作成しているものなど)。 – mrry

+0

こんにちは。私は再び投稿を修正しました。もう一度それを確認してください?キーポイントは、シャッフル後にtrain_labelsの値を取得する方法です。それは非常に混乱しています!どうもありがとうございました! – lemontree

+0

どのように 'error_rate()'関数を呼び出していますか?問題を見つけるのに役立つエラーメッセージはありますか? – mrry

答えて

0

理由はaccarayでうまく動作以下、あなたがnumpyのないtensoflow mothodsを使用しなければならないことです。

def correct_rate(out, labels): 
    arg = tf.argmax(out, 1) 
    arg = tf.cast(arg, tf.int32) 
    correct_prediction = tf.equal(labels, arg) 
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 
    return accuracy 

accr = correct_rate(logits, train_labels) 
print(sess.run(accr)) 
関連する問題