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