質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%

Q&A

0回答

2078閲覧

tensorflow mnist

kei_10

総合スコア37

0グッド

0クリップ

投稿2016/12/15 15:03

編集2016/12/16 09:50

http://domkade.hatenablog.jp/entry/2016/04/07/011016

上記の記事を参考にしてmnistサンプルを実行してみたのですが、
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
中止 (コアダンプ)
というエラーメッセージが出てしまいます。
なかなか解決策が見つからないのでご教授お願いします。

追記
http://qiita.com/toyolab/items/bccd03d4cb7795112ab6
上記のサイトを参考に環境を構築しました
実行コードは以下の通りです。

python

1from tensorflow.examples.tutorials.mnist import input_data 2mnist = input_data.read_data_sets('MNIST_data', one_hot=True) 3 4import tensorflow as tf 5sess = tf.InteractiveSession() 6 7x = tf.placeholder(tf.float32, shape=[None, 784]) 8y_ = tf.placeholder(tf.float32, shape=[None, 10]) 9 10W = tf.Variable(tf.zeros([784,10])) 11b = tf.Variable(tf.zeros([10])) 12 13sess.run(tf.initialize_all_variables()) 14 15y = tf.nn.softmax(tf.matmul(x,W) + b) 16 17cross_entropy = -tf.reduce_sum(y_*tf.log(y)) 18 19train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy) 20 21for i in range(1000): 22 batch = mnist.train.next_batch(50) 23 train_step.run(feed_dict={x: batch[0], y_: batch[1]}) 24 25correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) 26 27accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 28 29print(accuracy.eval(feed_dict={x: mnist.test.images, y_: mnist.test.labels})) 30 31def weight_variable(shape): 32 initial = tf.truncated_normal(shape, stddev=0.1) 33 return tf.Variable(initial) 34 35def bias_variable(shape): 36 initial = tf.constant(0.1, shape=shape) 37 return tf.Variable(initial) 38 39def conv2d(x, W): 40 return tf.nn.conv2d(x, W, strides=[1, 1, 1, 1], padding='SAME') 41 42def max_pool_2x2(x): 43 return tf.nn.max_pool(x, ksize=[1, 2, 2, 1], 44 strides=[1, 2, 2, 1], padding='SAME') 45 46W_conv1 = weight_variable([5, 5, 1, 32]) 47b_conv1 = bias_variable([32]) 48 49x_image = tf.reshape(x, [-1,28,28,1]) 50 51h_conv1 = tf.nn.relu(conv2d(x_image, W_conv1) + b_conv1) 52h_pool1 = max_pool_2x2(h_conv1) 53 54W_conv2 = weight_variable([5, 5, 32, 64]) 55b_conv2 = bias_variable([64]) 56 57h_conv2 = tf.nn.relu(conv2d(h_pool1, W_conv2) + b_conv2) 58h_pool2 = max_pool_2x2(h_conv2) 59 60W_fc1 = weight_variable([7 * 7 * 64, 1024]) 61b_fc1 = bias_variable([1024]) 62 63h_pool2_flat = tf.reshape(h_pool2, [-1, 7*7*64]) 64h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1) 65 66keep_prob = tf.placeholder(tf.float32) 67h_fc1_drop = tf.nn.dropout(h_fc1, keep_prob) 68 69W_fc2 = weight_variable([1024, 10]) 70b_fc2 = bias_variable([10]) 71 72y_conv=tf.nn.softmax(tf.matmul(h_fc1_drop, W_fc2) + b_fc2) 73 74cross_entropy = -tf.reduce_sum(y_*tf.log(y_conv)) 75train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) 76correct_prediction = tf.equal(tf.argmax(y_conv,1), tf.argmax(y_,1)) 77accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) 78sess.run(tf.initialize_all_variables()) 79for i in range(20000): 80 batch = mnist.train.next_batch(50) 81 if i%100 == 0: 82 train_accuracy = accuracy.eval(feed_dict={ 83 x:batch[0], y_: batch[1], keep_prob: 1.0}) 84 print("step %d, training accuracy %g"%(i, train_accuracy)) 85 train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5}) 86 87print("test accuracy %g"%accuracy.eval(feed_dict={ 88 x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

aja

2016/12/16 04:00

環境や環境設定の手順など、方法がある方がいいですが、このエラーはメモリー不足ではないでしょうか
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問