function test_example_CNN addpath(‘CNN/’); load mnist_uint8;
train_x = double(reshape(train_x’,28,28,60000))/255;%训练集使用minist数据,将图像进行归一化,图像大小28*28,总共60000张图像,除以255是将图像的像素值规约到0-1的范围内 test_x = double(reshape(test_x’,28,28,10000))/255;%将测试图像进行归一化 train_y = double(train_y’);%强制类型转换,转换为double型,训练标签大小为10*60000,因为数据集为手写体数字,总共有10类,60000张图像 test_y = double(test_y’);%测试集标签,大小为10*10000,共有10000张图像为测试集
%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you’ll get around 1.2% error
rand(‘state’,0)
cnn.layers = { struct(‘type’, ‘i’) %input layer struct(‘type’, ‘c’, ‘outputmaps’, 6, ‘kernelsize’, 5) %convolution layer,outputmaps卷积核个数6,kenelsize卷积核大小5*5 struct(‘type’, ‘s’, ‘scale’, 2) %sub sampling laye