MNIST for ML Beginnersの中の学習についてよくわかりません
batch_xs, batch_ys = mnist.train.next_batch(100)の部分がどのように動いているかなど教えていただけないでしょうか
よろしくお願いします
python
1import tensorflow as tf 2from tensorflow.examples.tutorials.mnist import input_data 3 4# データ読み込み 5mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) 6 7# placeholder用意 8x = tf.placeholder(tf.float32, [None, 784]) 9y_ = tf.placeholder(tf.float32, [None, 10]) 10 11W = tf.Variable(tf.zeros([784, 10])) 12b = tf.Variable(tf.zeros([10])) 13 14# Softmax Regressionを使う 15y = tf.nn.softmax(tf.matmul(x, W) + b) 16 17# 交差エントロピー 18cross_entropy = -tf.reduce_sum(y_ * tf.log(y)) 19 20train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) 21 22# 初期化 23init = tf.initialize_all_variables() 24sess = tf.Session() 25sess.run(init) 26 27# 学習 28for i in range(1000): 29 batch_xs, batch_ys = mnist.train.next_batch(100) 30 sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) 31 32# テストデータで予測 33correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) 34accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 35sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}) 36 #=> 0.91839999
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/18 17:00