hongyangqin / HyNote

HyNote 个人笔记

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tensorflow-ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[10000,32,28,28]

hongyangqin opened this issue · comments

问题描述

运行Deep MNIST for Experts的代码,在最后进行测试的时候

print("test accuracy %g"%accuracy.eval(feed_dict={
    x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))

出现以下错误

ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[10000,32,28,28]
	 [[Node: Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/gpu:0"](Reshape, Variable/read)]]

解决办法

显存不够导致,分批测试

batch_size = 50
batch_num = int(mnist.test.num_examples / batch_size)
test_accuracy = 0
    
for i in range(batch_num):
    batch = mnist.test.next_batch(batch_size)
    test_accuracy += accuracy.eval(feed_dict={x: batch[0],
                                              y_: batch[1],
                                              keep_prob: 1.0})

test_accuracy /= batch_num
print("test accuracy %g"%test_accuracy)

参考

ResourceExhaustedError in CNN/MNIST example (with GPU)