create target for neural network
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi all,
I had extracted feature vector of an image and saved it in a excel document. feature vector is 42x42 dimension. I don't know how to create target for this input so i can train the neural network. I need to do emotion classification. 5 classes. So, how do i create target vector and train the network?
댓글 수: 0
채택된 답변
Chandra Kurniawan
2012년 2월 13일
Hi, Remo
Feature vector that extracted from an image ideally m x 1 matrix.
You said that it's 42 x 42. Is it means 42 feature of 42 images??
If so, then you need to create 5 x 42 matrix of target.
First create matrix of zero 5 x 42.
for feature#1, this feature belong to which emotion? Let say 3rd class. Then you need to mark at first column 3rd row as 1.
t = [0 0 0 0 0 ... until 42
0 0 0 0 0 ...
1 0 0 0 0 ...
0 0 0 0 0 ...
0 0 0 0 0 ...
And so on.
I have an example below. In this example I have 5x5 feature vector. and 5x5 matrix of target.
p = [1 0 1 0 1
0 1 1 0 1
1 0 0 1 1
0 1 0 1 1
1 0 0 1 1];
t = [0 0 1 0 0
0 0 0 0 1
1 0 0 0 0
0 1 0 0 0
0 0 0 1 0];
PR = [0 1;0 1;0 1;0 1;0 1];
net = newff(PR,[5 25 25 5],{'logsig','logsig','logsig','logsig'},'traingda');
net.trainParam.epochs = 1500;
net.trainParam.goal = 0;
net = train(net,p,t);
Then try to simulate the first feature.
sim(net,p(:,1))
And the result :
ans =
0.0032
0.0003
0.9955
0.0000
0.0029
It means this inputs belong to 3rd class.
I hope this will helps.
댓글 수: 3
gfgf99
2015년 8월 31일
편집: gfgf99
2015년 8월 31일
Chandra Kurniawan Can you please explain above written code for more convince .
PR = [0 1;0 1;0 1;0 1;0 1]; net = newff(PR,[5 25 25 5],{'logsig','logsig','logsig','logsig'},'traingda'); net.trainParam.epochs = 1500; *net.trainParam.goal = 0; net = train(net,p,t);* .
Thank you.
Best regard
debasmita bhoumik
2016년 4월 9일
I have made two feature matrices ( the purpose was to classify weather infection exist or not in a leaf) of size 80x16 and 40x16 respectively. The first one was for training images(80 images with 16 features) and other is test images(40 images with 16 features). I had also classified them accurately using SVM classifier. Now i want to classify those same images with the help of NEURAL NETWORK. Please suggest what can I do
추가 답변 (1개)
Greg Heath
2012년 2월 14일
remo asked on 12 Feb 2012 at 12:29
>I had extracted feature vector of an image and saved it in a excel document. feature vector is 42x42 >dimension. I don't know how to create target for this input so i can train the neural network. I need to >do emotion classification. 5 classes
The input features must be column vectors. If you extract a feature matrix from an original matrix, you can convert it to a feature vector using the colon operator. For example, if you have a feature matrix fm with size(fm) = [ r, c ], then fv = fm(:) will be the corresponding feature vector with size(fv) = [ r*c, 1 ].
If you have N feature vectors from N images, the N columns form an input matrix, p, with size(p) = [ I N ] and I = r*c.
If the N images come from k classes, the corresponding target matrix, t, contains N columns of the k-dimensional unit matrix eye(k). The row containing the "1" is the class index for the corresponding input vector. size(t) = [ O N ] with O = k.
The output matrix is readily formed using the function IND2VEC. For example
>> t = full(ind2vec([ 1 3 5 2 4 ]))
t =
1 0 0 0 0
0 0 0 1 0
0 1 0 0 0
0 0 0 0 1
0 0 1 0 0
Given a feature vector, the resulting elements in the output vector can be interpreted as approximations to the input-conditional class posterior probabilities. The input vector is then assigned to the class corresponding to the maximum output.
A single hidden layer with H nodes is sufficient. The resulting node topology is I-H-O. This will result in Neq = N*O nonlinear equations to be "solved" for Nw = (I+1)*H+(H+1)*O unknown weights. For training to convergence, it is required that Neq >= Nw. However, the condition Neq >> Nw is preferable to mitigate real-world noise and measurement error. This is equivalent to requiring
H <= Hub is required but H << Hub is desired where the upper bound Hub is given by
Hub = ( Neq - O ) / ( I + O + 1 ).
A practical value for H can be obtained by trial and error keeping the above conditions in mind.
Hope this helps.
Greg
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!