How to use my HOG matrix in the SVM classifier? [closed]
I want to use the normalised HOG matrix which contains the features of my image. How to take the HoG matrix to use it in the SVM classifier? Does anyone has any idea how to do it?
Here is my HOG matrix:
FileStorage f("Normalised_HOG.xml", FileStorage::READ);
Here is my data labelling :
//assign label
Mat labels(num_files, 1, CV_32FC1);
float trainingData;
cv::Mat trainDataMat(num_files, DESCRIPT, CV_32FC1, trainingData);
Here is my SVM Parameters
//set up SVM Parameters
Ptr<cv::ml::SVM> svm = cv::ml::SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));
// Train the SVM
svm->train(trainDataMat, ROW_SAMPLE, labels);
cout << "Saving Trained SVM xml ..." << endl;
//svm->write(FileStorage("test.xml", FileStorage::WRITE));
svm->save("SVM.xml");
it seems your code is training then saving your svm classifier. once you have your .xml file you just have to load it and then use
svm->predict
to classify test images. is this comment revealing or do I misunderstood your question?Yes my code is to train then save the svm classifier but the problem is i don't know how to use the normalised HOG xml file containing the features of the image in training SVM. @guidovitale
something like:
Ptr<ml::svm> svm = ml::SVM::load<cv::ml::svm>(yourSVMfilename);
HOGd.compute(yourImage, descriptorsValues);
previsionLabel = svm->predict(descriptorsValues, noArray(), 0);
is it helpful?
Don't we have to use the xml file in the training set as shown below?
the .xml file contains the trained SVM data you'll use for prediction (i.e. support vectors, margin, etc...); try to open it with a txt editor to see that. once you have it, just use it for prediction (svm->predict...); it is meaningless to re-train another svm using the .xml as you did.
I think you have misunderstood my question. I need to take the HOG matrix (saved as xml file) and use it in training the SVM since it contains the features. How to do it ?
@Allison, you probably need to explain better, what exactly is inside your HOG matrix. (exact shape, type, how you got there, etc.)
you've already trained your svm when typing:
you don't need to train it another time