https://qiita.com/kkk3H/items/c3eb0d868170b29b0b87
上記の記事でmnistの様なデータセットを作ったのですが、それでmnist for expretsを動かそうとしたところ、実行結果でnanと出てしまいました。
画像の大きさは75x75です。
畳み込み処理のところがおかしいと思うのですが、どうすればいいのかわからずといったところです。
ご教示願います。
Jupyter Notebook
Python 3.6.4
TensorFlow 1.3.0
NumPy 1.13.3
以下コードです
python
1import tensorflow as tf 2import data_set 3 4data = data_set.read_data_sets(one_hot=True) 5 6def weight_variable(shape): 7 initial = tf.truncated_normal(shape, stddev=0.1) 8 return tf.Variable(initial) 9 10def bias_variable(shape): 11 initial = tf.constant(0.1, shape=shape) 12 return tf.Variable(initial) 13 14def conv2d(x, W): 15 return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME') 16 17def max_pool_2x2(x): 18 return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], 19 strides=[1, 2, 2, 1], padding='SAME') 20 21x = tf.placeholder(tf.float32, [None, 5625]) 22y_ = tf.placeholder(tf.float32, [None, 3]) 23 24x_image = tf.reshape(x, [-1, 75, 75, 1]) 25 26W_conv1 = weight_variable([10, 10, 1, 32]) 27b_conv1 = bias_variable([32]) 28 29h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1) 30h_pool1 = max_pool_2x2(h_conv1) 31 32W_conv2 = weight_variable([10, 10, 32, 64]) 33b_conv2 = bias_variable([64]) 34 35h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2) 36h_pool2 = max_pool_2x2(h_conv2) 37 38W_fc1 = weight_variable([7 * 7 * 64, 1024]) 39b_fc1 = bias_variable([1024]) 40 41h_pool2_flat = tf.reshape(h_pool2, [-1, 7*7*64]) 42h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1) 43 44keep_prob = tf.placeholder(tf.float32) 45h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob) 46 47W_fc2 = weight_variable([1024, 3]) 48b_fc2 = bias_variable([3]) 49 50y_conv = tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) 51 52cross_entropy = -tf.reduce_sum(y_ * tf.log(y_conv)) 53train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) 54correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1)) 55accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 56 57sess = tf.InteractiveSession() 58sess.run(tf.initialize_all_variables()) 59 60for i in range(2000): 61 batch = data.train.next_batch(100) 62 63 if i%50 == 0: 64 train_accuracy = accuracy.eval(feed_dict={x:batch[0], y_: batch[1], keep_prob: 1.0}) 65 print("step %d, training accuracy %g"%(i, train_accuracy)) 66 67 train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5}) 68 69print("test accuracy %g"%accuracy.eval(feed_dict={x: data.test.images, y_: data.test.labels, keep_prob: 1.0}))
以下実行結果です
WARNING:tensorflow:From /Users/anaconda3/envs/tf/lib/python3.6/site-packages/tensorflow/python/util/tf_should_use.py:175: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02. Instructions for updating: Use `tf.global_variables_initializer` instead. step 0, training accuracy nan step 50, training accuracy nan step 100, training accuracy nan step 150, training accuracy nan step 200, training accuracy nan step 250, training accuracy nan step 300, training accuracy nan step 350, training accuracy nan step 400, training accuracy nan step 450, training accuracy nan step 500, training accuracy nan step 550, training accuracy nan step 600, training accuracy nan step 650, training accuracy nan step 700, training accuracy nan step 750, training accuracy nan step 800, training accuracy nan step 850, training accuracy nan step 900, training accuracy nan step 950, training accuracy nan step 1000, training accuracy nan
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。