views:

1089

answers:

1

Hi.

Summary: I'm trying to do classification of some images depending on the angles between body parts.

I assume that human body consists of 10 parts(as rectangles) and find the center of each part and calculate the angle of each part by reference to torso. And I have three action categories:Handwave-Walking-Running. My goal is to find which test images fall into which action category.

Facts: TrainSet:1057x10 feature set,1057 stands for number of image. TestSet:821x10

I want my output to be 3x1 matrice each row showing the percentage of classification for action category. row1:Handwave row2:Walking row3:Running

Code:

actionCat='H';
[train_data_hw train_label_hw] = tugrul_traindata(TrainData,actionCat);
[test_data_hw test_label_hw] = tugrul_testdata(TestData,actionCat);


actionCat='W';
[train_data_w train_label_w] = tugrul_traindata(TrainData,actionCat);
[test_data_w test_label_w] = tugrul_testdata(TestData,actionCat);

actionCat='R';
[train_data_r train_label_r] = tugrul_traindata(TrainData,actionCat);
[test_data_r test_label_r] = tugrul_testdata(TestData,actionCat);

Train=[train_data_hw;train_data_w;train_data_r];
Test=[test_data_hw;test_data_w;test_data_r];

Target=eye(3,1);
net=newff(minmax(Train),[10 3],{'logsig' 'logsig'},'trainscg');
net.trainParam.perf='sse';
net.trainParam.epochs=50;
net.trainParam.goal=1e-5;
net=train(net,Train);

trainSize=size(Train,1);
testSize=size(Test,1);

if(trainSize > testSize)
pend=-1*ones(trainSize-testSize,size(Test,2));
Test=[Test;pend];
end


x=sim(net,Test);

Question: I'm using Matlab newff method.But my output is always an Nx10 matrice not 3x1. My input set should be grouped as 3 classes but they are grouped to 10 classes.

Thanks

+2  A: 
%% Load data : I generated some random data instead
Train = rand(1057,10);
Test = rand(821,10);
TrainLabels = randi([1 3], [1057 1]);
TestLabels = randi([1 3], [821 1]);

trainSize = size(Train,1);
testSize = size(Test,1);

%% prepare the input/output vectors (1-of-N output encoding)
input = Train';               %'matrix of size numFeatures-by-numImages
output = zeros(3,trainSize);  % matrix of size numCategories-by-numImages
for i=1:trainSize
    output(TrainLabels(i), i) = 1;
end

%% create net: one hidden layer with 10 nodes (output layer size is infered: 3)
net = newff(input, output, 10, {'logsig' 'logsig'}, 'trainscg');
net.trainParam.perf = 'sse';
net.trainParam.epochs = 50;
net.trainParam.goal = 1e-5;
view(net)

%% training
net = init(net);                            % initialize
[net,tr] = train(net, input, output);       % train

%% performance (on Training data)
y = sim(net, input);                        % predict
%[err cm ind per] = confusion(output, y);

[maxVals predicted] = max(y);               % predicted
cm = confusionmat(predicted, TrainLabels);
acc = sum(diag(cm))/sum(cm(:));
fprintf('Accuracy = %.2f%%\n', 100*acc);
fprintf('Confusion Matrix:\n');
disp(cm)

%% Testing (on Test data)
y = sim(net, Test');

Note how I converted from category label for each instance (1/2/3) to a 1-to-N encoding vector ([100]: 1, [010]: 2, [001]: 3)

Also note that the test set is currently not being used, since by default the input data is divided into train/test/validation. You could achieve your manual division by setting net.divideFcn to the divideind function, and setting the corresponding net.divideParam parameters.

I showed the testing on the same training data, but you could do the same for the Test data.

Amro
thanks..I'm still reviweving your code.Each time I run,I get different results probably because of random initial pick-up values.Is there a way to stabilize output ?Thanks again
tguclu
Since we are using a gradient descent search, it will always suffer from local minimas and the result will heavily depend on the initial values. To get a better estimate of the performance, you might want to look at other testing techniques such as n-fold cross-validation and bootstrapping (Remember that in my example, all values are just random)
Amro
I have changed random values with my own test and train data.Consecutive runs differ a lot i.e: %80 to %30 in accuracy.But testing same data on SVM results no big differences in consecutive runs.
tguclu
That is to be somewhat expected since in SVM learning involves optimization of a convex function (no false minima, unlike ANN). In your case I guess you could try tuning the various parameters: network structure, transfer functions, weight updating algorithm, etc... Usually what we do is to repeat the experiment several times and pick the network with the least prediction error, and report the average of those runs as an optimistic assessment. Again it would be worthwhile to lookup the other testing techniques I mentioned.
Amro
Thnks very much..Setting layer number to 10 stabilized the output in a much better way.
tguclu

related questions