Shape recognition by neural network

6 views (last 30 days)
Hello, I would like to ask which Neural Network should I choose. I want to recognition of 3 shape (Square,Circle,Triangle).
I learn my NN with 69 patterns (23 image of Square, 23 Circle etc). First network was "newp" and the second "newff". I have some answers but my network recognition e.g Triangle as Square and Circle or something like this. Any ideas ? Thank !
% PATTERNS
load PatternsSquare
load PatternsCircle
load PatternsTriangle
% SHAPE Square
P1=cell2mat(struct2cell(PatternsSquare));
PS=reshape(P1,40000,23);
% SHAPE Circle
P2=cell2mat(struct2cell(PatternsCircle));
PO=reshape(P1,40000,23);
% SHAPE Triangel
P3=cell2mat(struct2cell(PatternsTriangle));
PT=reshape(P1,40000,23);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NETWORK
P=[PS,PO,PT]; %MATRIX WITH ALL MY PATTERN
T=eye(3,69); %NETWORK ANSWER
%net = newp(P,T,'hardlim','learnp');
net=newff(P,T,[10 10],{'tansig' 'purelin'},'traingd');
net.trainParam.epochs = 50;
net.trainParam.goal=0.00001;
net = train(net,P,T);
Y=sim(net,P);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DISRUPTION
D=imread('T14.png'); % MY DISRUPTION PATTERN
D=im2bw(D);
D=double(D);
[m n] = size(D) ;
D = imresize(D, [200 200]);
[x y] = size(D);
PD=reshape(D,40000,1);
YD=sim(net,PD);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% DISPLAY
figure(1)
for i=1:1
subplot(1,2,i)
imshow(reshape(PD(:,i),200,200))
title('DISRUPTION')
subplot(1,2,2*i)
hintonw(YD(:,i))
title('NEURON: 1-Square, 2-Circle, 3-Triangle')
end

Accepted Answer

Greg Heath
Greg Heath on 2 Jun 2018
1.You have erroneouslyy defined PO and PT with P1
2. I think the argument in reshape should be (Pm,23,40000)
3. You have 2 hidden layers. One is sufficient.
4. I didn't look at Disruption and Display
Hope this helps.
Greg
  1 Comment
Pawel Osadnik
Pawel Osadnik on 5 Jun 2018
Edited: Pawel Osadnik on 5 Jun 2018
After when I change argument in reshape matrix occur an error:
Error using network/train (line 340)
Inputs and targets have different numbers of samples.
Error in SSN (line 26)
net = train(net,P,T);
My input data are 23 elements of 17.500 sampels (image piksel). And the data to chceck (DISRUPTION) are 1 of 17.500 and it's different.
It doesn't work.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!