代码表:
运行CNN测试时出现错误。我尝试了一些方法,但没有工作。
代码:
def evaluate_lenet5(learning_rate=0.1, n_epochs=200,
dataset='mnist.pkl.gz',
nkerns=[20, 50], batch_size=500):
rng = numpy.random.RandomState(23455)
将形状(batch_size,28 * 28)的光栅化图像矩阵重塑为4D张量,与我们的LeNetConvPoolLayer(28,28)兼容,是MNIST图像的大小。
# Load data
datasets = load_data(dataset)
train_set_x, train_set_y = datasets[0]
valid_set_x, valid_set_y = datasets[1]
test_set_x, test_set_y = datasets[2]
# Calculate the number of batches
n_train_batches = train_set_x.get_value(borrow=True).shape[0]
n_valid_batches = valid_set_x.get_value(borrow=True).shape[0]
n_test_batches = test_set_x.get_value(borrow=True).shape[0]
n_train_batches /= batch_size
n_valid_batches /= batch_size
n_test_batches /= batch_size
index = T.lscalar()
x = T.matrix('x')
y = T.ivector('y')
layer0_input = x.reshape((batch_size, 1, 28, 28))
...
错误:
ValueError: cannot reshape array of size 392000 into shape (28,28)
这些信息(输入)显示在错误下方:
Toposort index: 41
Inputs types: [TensorType(float64, matrix), TensorType(int64, vector)]
Inputs shapes: [(500, 784), (2,)]
Inputs strides: [(6272, 8), (8,)]
Inputs values: ['not shown', array([28, 28], dtype=int64)]
Outputs clients: [[InplaceDimShuffle{x,x,0,1}(Reshape{2}.0)]]
HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.
392000 = bath_size(500)* 28 * 28,所以,我不知道为什么......
如果有人能解决这个问题,我非常感激。 THX!