SVM Prediction
Hello, this is my first time posting here. I am currently working on age estimation and extracting features using Gabor Filters. I have decided to classify ages using a SVM, the training is successful and it does not take a long time since the feature vectors are only about 3000 in dimensions by a 1000 training samples.
The problem is that when I want to predict an image, the result returned is always 18 (I pass the feature vector of the testing image to the predict function of the SVM). But when I predict an age from the training set the result is always correct. I do not know why this is happening. Any help will be appreciated.
do {
sprintf(fullImagePath,"%s\\%s", imageDirectory, c_file.name);
string label = c_file.name;
float labelSubstring = atof(label.substr(15,2).c_str());
labels.push_back(labelSubstring);
Mat input = imread(fullImagePath,0);
featureVector = ExtractFeatures(input);
allFeatureVectors.push_back(featureVector.clone());
} while( _findnext( hFile, &c_file ) == 0 );
SVM svm;
CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::RBF;
params.gamma=0.000308;
params.C=1000;
svm.train(allFeatureVectors,labels,Mat(),Mat(),params);
Mat testingSVMBud = imread ("C:\\Users\\Gabriel\\Desktop\\ae2.JPG",0);
Mat fV = ExtractFeatures(testingSVMBud).clone();
float prediction = svm.predict(fV);
Thank you for your time!
I guess your training is not correct. From what you say, it seems that you're overfitting your training data, and therefore failing to generalize over the test data. You could try changing the C parameter to apply regularization
Changing the C parameter multiple times did nothing for the prediction. The result is always 18. I don't know what to do any more since I tried multiple solutions.
Posting your code here might be helpful to catch errors
Question Edited :) in the do while loop i am grabbing the images in the training set and extracting the Feature Vectors one by one and then adding them to the Feature Vector I am using to train the SVM. Thank you for reading my question!
I don't know which values of C you have tested, but 1000 seems a way too high value to me. Another question: is there any reason you're using an RBF kernel? I would also try to use the train_auto function with a k_fold setting to use cross-validation while training
Just a question: as the code you wrote, prediction is either -1 or 1. So how do you know the test image is predicted to be in 18 year old category?
Why is the prediction either -1 or 1? He's using several different labels (taken from the filename string), and therefore the prediction, as it is multiclass classification, will return the corresponding age
Thanks Lorena GdL, I supposed the SVM part of OpenCV just supported binary SVM. Then, in this case I think a polynomial kernel is better.
Hi, thanks for your suggestion! I used train_auto and the results are really off, the results being produced are different for each image so that is a step forward :). Thanks once again