2017-01-23 4 views
0

Tensorflowを使用するMNISTデータセット用のPythonコードがあります。独自のcsvファイルを使用してバッチを作成するpython

with tf.Session() as sess: 
     sess.run(tf.initialize_all_variables()) 
     for epoch in range(hm_epochs): 
      epoch_loss = 0 
      for _ in range(int(mnist.train.num_examples/batch_size)): 
       epoch_x, epoch_y = mnist.train.next_batch(batch_size) 
       _, c = sess.run([optimizer, cost], feed_dict={x: epoch_x, y: epoch_y}) 
       epoch_loss += c 
      print('Epoch: ', epoch, ' completed out of: ', hm_epochs, ' loss: ', epoch_loss) 
    correct = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1)) 

    accuracy = tf.reduce_mean(tf.cast(correct, 'float')) 

    print('Accuracy:', accuracy.eval({x: mnist.test.images, y: mnist.test.labels})) 

ライン:

epoch_x, epoch_y = mnist.train.next_batch(batch_size) 

は100

私の質問は、新しい行に次の行を置換する方法、ある大きさで毎回新しいバッチを作っている セッションは以下のとおりです。自分のCSVファイル(リストのリスト)があれば、それは私の新しいバッチになりますか? 私の現在のコードは次のようになります。

「nextbatchは」私は定義された関数がある
with tf.Session() as sess: 
    sess.run(tf.initialize_all_variables()) 
    for epoch in range(hm_epochs): 
     epoch_loss = 0 
     for _ in range(len(training_data_list) // batch_size): 
      epoch_x, epoch_y = training_data_list.nextbatch(batch_size) 
      _, c = sess.run([optimizer, cost], feed_dict={x: epoch_x, y: epoch_y}) 
      epoch_loss += c 
     print('Epoch: ', epoch, ' completed out of: ', hm_epochs, ' loss: ', epoch_loss) 
    correct = tf.equal(tf.argmax(prediction, 1), tf.argmax(y, 1)) 

    accuracy = tf.reduce_mean(tf.cast(correct, 'float')) 

    print('Accuracy:', accuracy.eval({x: inputs, y: targets})) 

。私はどんな提案に感謝

AttributeError: 'list' object has no attribute 'nextbatch' 

:しかし、私は次のエラーを取得するあなたが扱うオブジェクトを実装する必要が

stops = open('.../Desktop/stops_train.csv', 'r') 
training_data_list = stops.readlines() 
stops.close() 

答えて

0

:ところでD

を、「training_data_listは」から来ていますインデックス作成。 そのオブジェクトの内部にnextbatch関数を実装する必要があります。 mnistでnextbatchの実装を見ることができます。

+0

ありがとうございます。 一方、私はこれを使用しました: _範囲(_en * batch_size: batch_size] そしてそれは働いた。 – CrisH

関連する問題