hi, i'm using gui to create a recognition system to identify 2
classes.
for training, i have 150 image- parameter already extracted stored in
a trainfile.for testing, 50 image for each classes parameter not
extracted yet
here's what i did, i've created a gui that can load an image, extract
parameter from it and store in datatrain.csv. after all the 150
image's parameter stored, i use this code to test the rest of 100
image.
%~~~~~~~~~~~~~~~~~~~~~~~~use when test data~~~~~~~~~~~~~~~~~~~~~~
parameter=[num2str(M1) ',' num2str(M2) ',' num2str(M3) ',' num2str(M4)
',' num2str(M5) ',' num2str(M6) ',' num2str(M7) ',' num2str(perimeter)
',' num2str(area) ',' num2str(xbar) ',' num2str(ybar) ];
data=[filename ',' num2str(M1) ',' num2str(M2) ',' num2str(M3) ','
num2str(M4) ',' num2str(M5) ',' num2str(perimeter) ',' num2str(M6) ','
num2str(M7) ',' num2str(area) ',' num2str(xbar) ',' num2str(ybar)];
fid = fopen('C:\Documents and Settings\winxp\My Documents\MATLAB
\MATLABDATA\datatest.csv','a+');
fprintf(fid,[parameter,'\n']);
fclose(fid);
fid = fopen('C:\Documents and Settings\winxp\My Documents\MATLAB
\MATLABDATA\datatest.txt','a+');
fprintf(fid,[data,'\r\n']);
fclose(fid);
set(handles.edit45,'String','Load completed')
end
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
%~~~~~~~~~~~[L1 L2 1];first hidden layer,second & output layer~~~~~
layer = [11 15 1];
myepochs = 30;
attemption = 1; %i;
mytfn = {'tansig' 'tansig' 'purelin'};
%~~~~~~load data~~~~~~~~~~~~~~~~~~~~~~~
m = xlsread('C:\Documents and Settings\winxp\My Documents
\MATLAB\MATLABDATA\datatrain.csv');
mt = xlsread('C:\Documents and Settings\winxp\My Documents
\MATLAB\MATLABDATA\datatest.csv');
%~~~~~~convert the data in Matrix form~~~~
[row,col] = size(m);
[row1,col1] = size(mt);
P = m(1:row,1:10)';
Pt= mt(1:row1,1:10)';
T1 = m(1:row, col)'; % target data for training...last
column
Tt = mt(1:row1, col1)'; % target data for testing
net = newff([minmax(P)],layer,mytfn,'trainlm'); %nnet
net.trainParam.epochs = myepochs; % how many time newff will
repeat the training
net.trainParam.showWindow = false;
net.trainParam.showCommandLine = true;
net = train(net,P,T1); % start training newff with input P
and target T1
Y = sim(net,P); % training
Yt= sim(net,Pt); % test newff using testing data
%~~~~~~~final result of the neural network~~~~~~~~
[r,c]=size(Yt);
result=Yt(c);
if result>0.7
error=1-result;
set(handles.edit39,'String','PET')
set(handles.edit40,'String',num2str(error))
set(handles.edit41,'String','completed')
data=[num2str(result) ];
fid = fopen('C:\Documents and Settings\winxp\My Documents
\MATLAB\MATLABDATA\record.csv','a+'); %use it when test data
fprintf(fid,[data,'\n']);
fclose(fid);
else
set(handles.edit39,'String','Non-PET')
set(handles.edit40,'String',num2str(result))
set(handles.edit41,'String','completed')
data=[num2str(result) ];
fid = fopen('C:\Documents and Settings\winxp\My Documents
\MATLAB\MATLABDATA\record.csv','a+');
fprintf(fid,[data,'\n']);
fclose(fid);
end
when i click pushbutton4, an image will load, and identify the type of
the image. i repeat this until all the 100 image are identified. then
i calculate the correct image percentage.
question:
1. is what i'm doing correct?
2. why does it seem like training when testing the image?
3. when i test the same image again, the answer is different from
before. why?
can u help me fix this code?
tq
|
|
0
|
|
|
|
Reply
|
amy
|
1/25/2011 4:51:05 AM |
|
amy <twintwinkle_twee@yahoo.com> wrote in message <c9917938-0202-4158-b270-cec8936ae638@a28g2000prb.googlegroups.com>...
> hi, i'm using gui to create a recognition system to identify 2
> classes.
> for training, i have 150 image- parameter already extracted stored in
> a trainfile.for testing, 50 image for each classes parameter not
> extracted yet
>
> here's what i did, i've created a gui that can load an image, extract
> parameter from it and store in datatrain.csv. after all the 150
> image's parameter stored, i use this code to test the rest of 100
> image.
>
>
> %~~~~~~~~~~~~~~~~~~~~~~~~use when test data~~~~~~~~~~~~~~~~~~~~~~
> parameter=[num2str(M1) ',' num2str(M2) ',' num2str(M3) ',' num2str(M4)
> ',' num2str(M5) ',' num2str(M6) ',' num2str(M7) ',' num2str(perimeter)
> ',' num2str(area) ',' num2str(xbar) ',' num2str(ybar) ];
> data=[filename ',' num2str(M1) ',' num2str(M2) ',' num2str(M3) ','
> num2str(M4) ',' num2str(M5) ',' num2str(perimeter) ',' num2str(M6) ','
> num2str(M7) ',' num2str(area) ',' num2str(xbar) ',' num2str(ybar)];
> fid = fopen('C:\Documents and Settings\winxp\My Documents\MATLAB
> \MATLABDATA\datatest.csv','a+');
> fprintf(fid,[parameter,'\n']);
> fclose(fid);
>
> fid = fopen('C:\Documents and Settings\winxp\My Documents\MATLAB
> \MATLABDATA\datatest.txt','a+');
> fprintf(fid,[data,'\r\n']);
> fclose(fid);
>
> set(handles.edit45,'String','Load completed')
>
> end
>
> % --- Executes on button press in pushbutton4.
> function pushbutton4_Callback(hObject, eventdata, handles)
> %~~~~~~~~~~~[L1 L2 1];first hidden layer,second & output layer~~~~~
>
> layer = [11 15 1];
> myepochs = 30;
> attemption = 1; %i;
> mytfn = {'tansig' 'tansig' 'purelin'};
>
> %~~~~~~load data~~~~~~~~~~~~~~~~~~~~~~~
> m = xlsread('C:\Documents and Settings\winxp\My Documents
> \MATLAB\MATLABDATA\datatrain.csv');
> mt = xlsread('C:\Documents and Settings\winxp\My Documents
> \MATLAB\MATLABDATA\datatest.csv');
>
> %~~~~~~convert the data in Matrix form~~~~
> [row,col] = size(m);
> [row1,col1] = size(mt);
>
>
> P = m(1:row,1:10)';
>
> Pt= mt(1:row1,1:10)';
>
> T1 = m(1:row, col)'; % target data for training...last
> column
> Tt = mt(1:row1, col1)'; % target data for testing
>
>
> net = newff([minmax(P)],layer,mytfn,'trainlm'); %nnet
> net.trainParam.epochs = myepochs; % how many time newff will
> repeat the training
> net.trainParam.showWindow = false;
> net.trainParam.showCommandLine = true;
> net = train(net,P,T1); % start training newff with input P
> and target T1
>
> Y = sim(net,P); % training
> Yt= sim(net,Pt); % test newff using testing data
>
> %~~~~~~~final result of the neural network~~~~~~~~
> [r,c]=size(Yt);
> result=Yt(c);
>
>
> if result>0.7
> error=1-result;
> set(handles.edit39,'String','PET')
> set(handles.edit40,'String',num2str(error))
> set(handles.edit41,'String','completed')
> data=[num2str(result) ];
> fid = fopen('C:\Documents and Settings\winxp\My Documents
> \MATLAB\MATLABDATA\record.csv','a+'); %use it when test data
> fprintf(fid,[data,'\n']);
> fclose(fid);
>
> else
> set(handles.edit39,'String','Non-PET')
> set(handles.edit40,'String',num2str(result))
> set(handles.edit41,'String','completed')
> data=[num2str(result) ];
> fid = fopen('C:\Documents and Settings\winxp\My Documents
> \MATLAB\MATLABDATA\record.csv','a+');
> fprintf(fid,[data,'\n']);
> fclose(fid);
>
> end
>
> when i click pushbutton4, an image will load, and identify the type of
> the image. i repeat this until all the 100 image are identified. then
> i calculate the correct image percentage.
>
> question:
> 1. is what i'm doing correct?
> 2. why does it seem like training when testing the image?
> 3. when i test the same image again, the answer is different from
> before. why?
> can u help me fix this code?
>
> tq
could u plz show me your code on training...ie trainfile.m...???working on the same project.. need help....!thnks!
|
|
0
|
|
|
|
Reply
|
shinucool (3)
|
3/13/2011 7:06:04 AM
|
|
|
1 Replies
565 Views
(page loaded in 0.055 seconds)
|