How to get coordinate from Neural Network training image?

2 views (last 30 days)
I tried to study Neural Network tracking object from this thesis http://www.waset.org/journals/waset/v6/v6-50.pdf . I train image with newff. I define 2 node for output but it show double value not show coordinate. I don't know how to get coordinate from neural network. After I use function train and sim the result of variable A2 are [0.0658;0.0989]. please help me, how to get coordinate from Neural Network training image like the thesis? this is my code.
%Read image for train
I1 = imread('1.jpg');
I2 = imread('2.jpg');
I3 = imread('3.jpg');
G1 = rgb2gray(I1);
G2 = rgb2gray(I2);
G3 = rgb2gray(I3);
I1 = downsample(G1,9);
I2 = downsample(G2,9);
I3 = downsample(G3,9);
D1 = im2double(I1);
D2 = im2double(I2);
D3 = im2double(I3);
%Read image for test
I_test = imread('test_img.jpg');
G_test = rgb2gray(I_test);
I_test = downsample(G_test,9);
D_test = im2double(I_test);
M_test = D_test(:);
S1=10;
target = eye(2,3); %create target matrix.
M1 = D1(:);
M2 = D2(:);
M3 = D3(:);
M = M1; %reshape pattern for train
M(:,2) = M2;
M(:,3) = M3;
[R,Q]=size(M);
S2 = 2; % set output to 2 node
P = M;
net = newff(minmax(P),[S1 S2],{'logsig' 'logsig'});
P = M;
T= target;
net.performFcn = 'sse';
net.trainParam.goal = 0.1;
net.trainParam.show = 20;
net.trainParam.epochs = 5000;
net.trainParam.mc = 0.95;
[net,tr] = train(net,P,T);
netn = net;
netn.trainParam.goal = 0.6;
netn.trainParam.epochs = 300;
[netn,tr] = train(netn,P,T);
A2 = sim(netn,M(:,3));
%the result of variable A2 are [0.0658;0.0989]

Answers (3)

Greg Heath
Greg Heath on 31 Mar 2012
>[net,tr] = train(net,P,T);
OK to here. The net is a classifier to recognize 3 types of images.
>netn = net;
>netn.trainParam.goal = 0.6;
>netn.trainParam.epochs = 300;
>[netn,tr] = train(netn,P,T);
WHY in the world was netn created??
>A2 = sim(netn,M(:,3));
Why not named A3?
%the result of variable A2 are [0.0658;0.0989]
Which looks OK because the target is [0.0 ; 0.0]
Delete every thing below the line "OK to here". Then add
A = sim(net,M)
ERROR = T - A
MSE = mse(ERROR)
MSE00 = mse(T-repmat(mean(T,2),1,3))
NMSE = MSE/MSE00 % Normalized Mean-Square-Error
R2 = 1- NMSE % Coefficient of Variation (See Wikipedia)
Please paste the results of these 6 added lines (Note: no semicolon)
Hope this helps.
Greg

Max333
Max333 on 2 Apr 2012
I don't understand how to get coordinate , the result of that code is this.
>> A = sim(net,M)
A =
0.9492 0.0234 0.0639
0.0028 0.7804 0.2082
>> ERROR = T - A
ERROR =
0.0508 -0.0234 -0.0639
-0.0028 0.2196 -0.2082
>> MSE = mse(ERROR)
MSE =
0.0165
>> MSE00 = mse(T-repmat(mean(T,2),1,3))
MSE00 =
0.2222
>> NMSE = MSE/MSE00
NMSE =
0.0741
>> R2 = 1- NMSE
R2 =
0.9259

Greg Heath
Greg Heath on 3 Apr 2012
As I stated above, the network is a classifier which will assign an input to one of three classes. You have to assign the coordinates that are associated with that class.
To make it easier to understand, make these changes
%target = eye(2,3)
target = eye(3)
class = vec2ind(target)
.
.
.
A = sim(net,M)
classA = vec2ind(A)
Hope this helps.
Greg

Community Treasure Hunt

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

Start Hunting!