在tensorflow教程深入mnist这一部分,如果照搬CNN代码,会出现terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Process finished with exit code 134 (interrupted by signal 6: SIGABRT)这个错误,这是因为一次测试10000幅mnist图像会导致电脑内存不足甚至死机,对此我们可以减少测试的数据集。
可以添加如下代码:
test_batch = mnist.test.next_batch(1000)
acc_forone=compute_accuracy(test_batch[0], test_batch[1])
#coding=utf-8
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
def compute_accuracy(v_xs,v_ys):
globa