matlab - Problems with network input size -
i've been working on character recognition program in matlab sometime , asked couple questions on stackoverflow , received feedback. figured try luck again.
problem: i'm getting error in train of network.
"input 1 size not match net.inputs{1}.size."
i'm using pictures below. want train network using picture 1 recognize contents in picture 2. before can train network, pre-process images. wrote program extract each letter in image , convert image binary matrix. example, if grid each letter 10x10 in first image have 10x10x4 matrix , second image 10x10x2.
so have target matrix 10x10x4 , input matrix 10x10x2.
to train network need reshape each 10x10 layer in images each layer "converted" row using (:) operator. target matrix has size of 4x100 , input matrix size of 2x100.
training: it's understanding in order network trained recognize characters in first image (targets), need train network targets. thusly, use following code.
[net, tr] = trainnnet(100, train, targets);
to perform actual recognition, simulate net each row in input matrix , record outputs using indices. step through input matrix row-wise using for/loop, simulate network, , send outputs findmatch function. functions purpose find rows in targets input array matches. not important error.
[r c d] = size(input); k = 1:d input = input(k,:); outputs = round(sim(net,input)); [matched(:,k), ind(:,k)] = findmatch(outputs, targets); end
i know why keep getting error "input 1 size not match net.inputs{1}.size." program works fine if have 1 letter in input image. suggestions appreciated.
edit: mentioned above used (:) operator. mistake. use following code reshape matrix need.
[r c d] = size(input); c = permute(input,[3 2 1]); newinput = reshape(c,d,r*c,1);
so example, given following matrix:
input(:,:,1) = [1 2;3 4]; input(:,:,2) = [5 6;7 8]; input(:,:,3) = [9 10;11 12];
you get:
newinput = [1,2,3,4;5,6,7,8;9,10,11,12];
also, made mistake in stating works 1 letter. works 1 letter only if train network letter wanting recognize. trained using,
[net, tr] = trainnnet(100, input, targets);
where input 1x100 (for 1 letter).
assuming understand train network use target values targets , inputs, found way make simulation run.
for inputs in simulation, have add rows of zeros resulting input matrix same size target matrix.
Comments
Post a Comment