Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Kindly help me to get out of this. Regarding Neural network

Asked by Muzafar Pandit on 11 Feb 2013

I'm currently woking on pedestrian classification. I have a IEEE paper that I need to implement. I have a data set "INRIA", which consists of positive images(1126) and negative images(1218). I'm using coHOG as a feature extractor. On extracting the features from negative folder(1218 image), i got .mat file which consists of two variables "x" which contains 1218*1344 features and "y" which consists of 1*1218 elements. When I am presenting this .mat file to the pattern net (toolbox) with x as input and y as target, NN doesn't show any progress, neither it performs any epoch. I don't know what should be input and target to a NN. What should be the no. of classes( i think classes are two as pedestrian and non pedestrian). Kindly help me from last 10 days I am working on it but I have done nothing....


Muzafar Pandit


No products are associated with this question.

3 Answers

Answer by Greg Heath on 17 Feb 2013
Accepted answer

xn=x'; %size of x is: 1344 x 1218

yn=y; %size of y is: 1 x 1218

clear x y

load inriapos1new

x=xp'; %size of xp is 1344 x 1126

y=yp; %size of yp is 1 x 1126



outclass=[ones(60,1),zeros(60,1) zeros(50,1),ones(50,1)];

1. Your code, notation, and reuse of variable names are confusing.

2. You never use the commands size and whos to double check variable size.

3. Use variable names that indicate the function of the variable

4. Use xn,tn for input and target negatives, xp,tp for positives, x,t for the combination and y for the nnet output.

5. Use the command whos at any time to check the sizes of all variables

 sizexn0 = size(xn0)  %[ 1344 1218 ]
 sizetn = size(tn)  %[ 1    1218 ]  from [ zeros(1,1218) ]
 sizexp0 = size(xp0)  %[ 1344 1126 ]
 sizetp = size(yp)  %[ 1    1126 ]  from [ ones(1,1126) ]
 whos                % doublecheck

% Use feature extraction function to reduce input dimensionality to 60 ( for example)

 sizexn  = size(xn)    % [ 60 1218 ]
 sizexp  = size(xp)    % [ 60 1126 ]
 x = [ xn , xp ];  % [ 60 2344]
 t = [ tn , tp ];  % [ 1 2344] from  [ zeros(1,1218) , ones(1,1126) ];

Hope this helps

Thank you for formally accepting my answer!



Muzafar Pandit on 18 Feb 2013

I did same but still it is showing error,

Inputs and targets have different numbers of samples.

Greg Heath on 19 Feb 2013

Impossible if you followed my code.

Please itersperse size and who statements to find out where you made the error.


Muzafar Pandit on 24 Feb 2013

I will send u all the code and data set, could you please correct it? Let me know your wish about this.

Greg Heath
Answer by Sarah on 11 Feb 2013

Hi, first of all you should clearly set the num of classes, say 'c'. Then the num of examples you have of each class, say 'n'. Each example should be a vector NOT matrix. Ip matrix is ((n*c)*k), where k is num of features in each example. The target matrix size is c*(n*c).

K must be as small as possible. Roughly talk, if n =70, then k should be around 7.

Hope this helps.


Answer by Greg Heath on 13 Feb 2013

It looks like you have an I-H-O patternnet classifier with

[ I N ] = size(input) = [ 1134 2344] % 2344=1218+1126

[ O N ] = size(target) = [ 1 2344] % zeros and ones

Hopefully with

(N*O-O)/(I+O+1) ~ N/(I+2) >> H for O=1 and N >> 1.

Both classes must have the same number of extracted features, I.

The target matrix contains only zeros and ones.

help/doc patternnet % 'tansig', 'logsig' and 'trainscg'

Your biggest challenge is the feature reduction of an image to a vector with a reasonably small dimension, I. With only 2 classes, it is hard for me to believe that more than several tens of features are necessary.

While you are in the debugging mode I suggest only using a subsample ( e.g., several hundreds?) of the data vectors.

Then, for prime-time you can either design one classifier using all of the data or design several classifiers designed on separate subsets of the data and outputting a vote for either class. Then, with an odd number of classifiers, assign the input to the class that has the most votes.

Search "committee" and "ensemble" in the Newsgroup and for more details on combining nets.

Hope this helps.

Thank you for formally accepting my answer



Greg Heath on 13 Feb 2013

It would probably help us help you if you posted code.


Muzafar Pandit on 17 Feb 2013

%code is here


format compact

load testinria3

xn=x'; %size of x is: 1344 x 1218

yn=y; %size of y is: 1 x 1218

clear x y

load inriapos1new

x=xp'; %size of xp is 1344 x 1126

y=yp; %size of yp is 1 x 1126



outclass=[ones(60,1),zeros(60,1) zeros(50,1),ones(50,1)];

     %neural network
     [net tr]=train(net,x,y); % now it shows error here which is given below

save CVOGtraffic net

the error it showing now is is at statement [net tr]=train(net,x,y);

Error using trainscg (line 104)

Inputs and targets have different numbers of samples.

Error in network/train (line 106)

[net,tr] =


Error in test_real_nn (line 27)

[net tr]=train(net,x,y);

Greg Heath

Contact us