IMPORTANT NOTE: THERE IS A CORRECTION AT THE BOTTOM!
Mr. Hinton et all has published a deep learning example named mnistdeepauto
at his page: http://www.cs.toronto.edu/~hinton/MatlabForSciencePaper.html
I tried to run this example but encountered the below error
error: vertical dimensions mismatch (1x768320 vs 1x889840)
although I did everything right. This might happen because of a
change in the test data of MNIST after this example is published.
So it may not be the program but the data causing the error.
In any case you can find my solution below. The changes has to be done
in the makebatches.m script.
Cheers.
Ali Riza SARAL
octave:15 digitdata=[];
octave:16 targets=[];
octave:17 clc
octave:18 clear all
octave:19 digitdata=[];
octave:20 targets=[];
octave:21 load test0; digitdata = [digitdata; D]; targets = [targets; repmat([1 0 0 0 0 0 0 0 0 0], size(D,1), 1)];
octave:22 load test1; digitdata = [digitdata; D]; targets = [targets; repmat([0 1 0 0 0 0 0 0 0 0], size(D,1), 1)];
error: vertical dimensions mismatch (1x768320 vs 1x889840) <========================ERROR
octave:22 load test2; digitdata = [digitdata; D]; targets = [targets; repmat([0 0 1 0 0 0 0 0 0 0], size(D,1), 1)];
error: vertical dimensions mismatch (1x768320 vs 1x809088)
octave:22 load test3; digitdata = [digitdata; D]; targets = [targets; repmat([0 0 0 1 0 0 0 0 0 0], size(D,1), 1)];
error: vertical dimensions mismatch (1x768320 vs 1x791840)
octave:22 load test4; digitdata = [digitdata; D]; targets = [targets; repmat([0 0 0 0 1 0 0 0 0 0], size(D,1), 1)];
error: vertical dimensions mismatch (1x768320 vs 1x769888)
octave:22 load test5; digitdata = [digitdata; D]; targets = [targets; repmat([0 0 0 0 0 1 0 0 0 0], size(D,1), 1)];
error: vertical dimensions mismatch (1x768320 vs 1x699328)
octave:22 load test6; digitdata = [digitdata; D]; targets = [targets; repmat([0 0 0 0 0 0 1 0 0 0], size(D,1), 1)];
error: vertical dimensions mismatch (1x768320 vs 1x751072)
octave:22 load test7; digitdata = [digitdata; D]; targets = [targets; repmat([0 0 0 0 0 0 0 1 0 0], size(D,1), 1)];
error: vertical dimensions mismatch (1x768320 vs 1x805952)
octave:22 load test8; digitdata = [digitdata; D]; targets = [targets; repmat([0 0 0 0 0 0 0 0 1 0], size(D,1), 1)];
error: vertical dimensions mismatch (1x768320 vs 1x763616)
octave:22 load test9; digitdata = [digitdata; D]; targets = [targets; repmat([0 0 0 0 0 0 0 0 0 1], size(D,1), 1)];
error: vertical dimensions mismatch (1x768320 vs 1x791056)
octave:22 load test0;
octave:23 size(D)
ans =
1 768320
octave:24 load test1; size(D)= 1 889840
octave:26 load test2; size(D)= 1 809088
octave:28 load test3; size(D)= 1 791840
octave:30 load test4; size(D)= 1 769888
octave:32 load test5; size(D)= 1 699328
octave:34 load test6; size(D)= 1 751072
octave:36 load test7; size(D)= 1 805952
octave:38 load test8; size(D)= 1 763616
octave:40 load test9; size(D)= 1 791056
octave:42 clc
octave:43 clear all
octave:44 digitdata=[];
octave:45 targets=[];
octave:46 load test0; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([1 0 0 0 0 0 0 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:47 size(digitdata)
ans =
980 784
octave:48 size(targets)
ans =
980 10
octave:49 load test1; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 1 0 0 0 0 0 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:50 size(digitdata)= 2115 784
octave:51 size(targets)= 2115 10
octave:52 load test2; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 0 1 0 0 0 0 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:54 size(digitdata)= 3147 784
octave:55 size(targets)= 3147 10
octave:56 diary off
octave:58 clc
octave:59 clear all
octave:60 digitdata=[];
octave:61 targets=[];
octave:62 load test0; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([1 0 0 0 0 0 0 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:63 load test1; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 1 0 0 0 0 0 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:64 load test2; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 0 1 0 0 0 0 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:65 load test3; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 0 0 1 0 0 0 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:66 load test4; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 0 0 0 1 0 0 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:67 load test5; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 0 0 0 0 1 0 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:68 load test6; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 0 0 0 0 0 1 0 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:69 load test7; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 0 0 0 0 0 0 1 0 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:70 load test8; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 0 0 0 0 0 0 0 1 0], size(reshape(D,size(D,2)/784,784),1),1)];
octave:71 load test9; digitdata = [digitdata; reshape(D,size(D,2)/784,784)]; targets = [targets; repmat([0 0 0 0 0 0 0 0 0 1], size(reshape(D,size(D,2)/784,784),1),1)];
octave:72 size(digitdata)
ans =
10000 784
octave:73 size(targets)
ans =
10000 10
octave:74 diary off
IMPORTANT NOTE:
I noticed that the program gives the below test output with my modifications suggested above:
The above algorithm destroys the test input data although it creates correct size batches.
The correct change is given below:
converter.m converts the mnist database data as below:
---------------------------------
for i=1:10, % read number i 's 1000 raw labels and 784 pixel 1000 raw images , 1 to 10
fprintf('.');
rawimages = fread(f,28*28*n,'uchar'); %images
rawlabels = fread(g,n,'uchar'); %labels
rawimages = reshape(rawimages,28*28,n); % 784 x 1000
for j=1:n,
fprintf(Df{rawlabels(j)+1},'%3d ',rawimages(:,j)); %fprintf to the Df recorded file pointer according to the raw label value, number j's images.
% each number read is written to the corresponding testX.ascii file. 1000 cases and 784 pixels each
end;
end;
fprintf(1,'\n');
-------------------------------------------------
It should be:
-------------------------------------------------
for i=1:10, % read number i 's 1000 raw labels and 784 pixel 1000 raw images , 1 to 10
fprintf('.');
rawimages = fread(f,28*28*n,'uchar'); %images
rawlabels = fread(g,n,'uchar'); %labels
rawimages = reshape(rawimages,28*28,n); % 784 x 1000
for j=1:n,
fprintf(Df{rawlabels(j)+1},'%3d ',rawimages(:,j)); %fprintf to the Df recorded file pointer according to the raw label value, number j's images.
fprintf(Df{rawlabels(j)+1},'\n'); % each number read is written to the corresponding testX.ascii file. 1000 cases and 784 pixels each
end;
end;
%fprintf(1,'\n');
--------------------------------------------------
The result is:
and mnist_error file
---------------------------------------------------
# Created by Octave 3.4.3, Fri Oct 05 01:11:04 2018 Turkey Standard Time
# name: test_err
# type: scalar
36.63076254519869
# name: train_err
# type: scalar
36.96345981717504