Help on Gesture recognition code?

I'm doing a project on gesture recognition using Neural Networks. The training Network is RBF net, and the net is saved as gesture1net in an m-file train.m . However, when I load the network, I get an error message that says "undefined variable or function gesture1net". Can anyone tell me why that is? Here's part of the code:
1) train.m
% This program is used to make the neural network for the identification of the gesture1.
clc;
clear all;
% Load the sample images (of different poses) to make net for gesture1
img1=imread('firsgesture1.jpg');
img2=imread('firsgesture2.jpg');
img3=imread('firsgesture3.jpg');
% Crop the sample images
imgcpd1=imcrop(img1);
imgcpd2=imcrop(img2);
imgcpd3=imcrop(img3);
% Train the network. p is the input vector and t is the target vector
p=[imgcpd1,imgcpd2,imgcpd3];
t=[imgcpd1,imgcpd1,imgcpd1];
p=double(p);
t=double(t);
net=newrb(p,t,.001,.1,1000,25); %train using RBF net
save('gesture1net','net'); %save the network
2) trackrecog.m
% MATLAB program for real time hand tracking and gesture identification
clc;
clear all;
close all;
train;
closepreview;
vid = videoinput('winvideo', 1, 'YUY2_640x480'); %specify the video adaptor
src = getselectedsource(vid);
vid.ReturnedColorspace = 'grayscale'; %define the color format to GRAYSCALE
vid.FramesPerTrigger = 1;
preview(vid); %preview the video object
load gesture1net; %load the network for each gesture
imgref1=imread('refimg1.jpg'); %loading the reference image for each gesture
imgcrpd1=imcrop(imgref1); %crop the reference images
imgcrpd1=double(imgcrpd1);
imgtrained1=sim(gesture1net,imgcrpd1) ; %train the cropped reference images_
Thank You!

 Risposta accettata

Do you get the error message on the load statement? Or on something you do right after the load? With that form of "load" the variable that would be created would be named "net".
Also, your invocation of train should be only
train
and not
train.m

10 Commenti

Oh, I'm so sorry, the train.m was a typo! The error is in the last line,
imgtrained1=sim(gesture1net,imgcrpd1);
You're right, it's after the load statement. Sorry for not being clear earlier!
The variable you are saving is named "net", not "guesture1net". load() that does not have any output arguments restores variables under their original name.
You can change your train.m to have
gesture1name = newrb(p,t,.001,.1,1000,25); %train using RBF net
save('gesture1net','gesture1net'); %save the network
You're calling a function that is supposed to return Pi but in your code, because of some conditions on if statements, for loops, or while loops, or case statements, the code that is supposed to set Pi never gets called.
Did the error come out with the original network or after it was loaded?
Your "train" routine is a script rather than a function, so any variables it creates are still in the workspace. You would not need to save() or load() to access the network.
Pruthvi
Pruthvi il 8 Feb 2014
Modificato: Pruthvi il 8 Feb 2014
I converted the imgcrpd1 to double and got rid of the previous error. And then I scrapped the save() and load() functions and got this error :
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> calcpd at 81
pd = [pd; Pc{j,ts-d}];
Error in ==> network.sim at 186
Pd = calcpd(net,TS,Q,Pc);
Error in ==> trackrecog at 37
imgtrained1=sim(net1,imgcrpd1); %train the cropped reference images
Are all of the gesture images the same size? Are you cropping them to exactly the same size?
You need to learn how to use the debugger. Once you do that you can figure out what the dimensions of pd are and what the dimensions of whatever array is inside the cell Pc{j,ts-d}, and you can see that the numbers of columns don't match. I don't know why - you have to figure out why you are wanting to vertically stack arrays that don't have the same number of columns. You can't tack on a 10 by 10 array onto the bottom of a 2 by 2 array - their numbers of columns don't match.
Pruthvi
Pruthvi il 10 Feb 2014
Thanks a million for your help! I found out where I went wrong, and the program works now! Thanks again!
1. train is a MATLAB function in the NNTBX
help train
doc train
I recommend using another name.
2. I am very suspicious of the inputs in
net = newrb(p,t,.001,.1,1000,25); %train using RBF net
H = 1000 indicates to me that the net is probably overfit, overtrained, and, probably, unsuccessful on nontraining data.
3. Will you please post the results of the command
whos
so that I can see the dimensions of your variables?
Hope this helps.
Greg
Pruthvi
Pruthvi il 13 Feb 2014
Well, the performance doesn't meet the goal even after H=1000. The MSE is 126.07. But you're right, the network isn't able to classify other images, and the program doesn't work very well. Here's our code. Could you suggest any changes to make it better?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by