Asked by remo
on 12 Feb 2012

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?

Answer by Chandra Kurniawan
on 13 Feb 2012

Accepted Answer

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.

remo
on 14 Feb 2012

hi chandra,

thanks for ur time in answering my question. from ur explanation, i can understand the concept of creating the target vector. thank you sir.

gfgf99
on 31 Aug 2015

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
on 9 Apr 2016

Sign in to comment.

Answer by Greg Heath
on 14 Feb 2012

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

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.