【发布时间】:2014-03-26 08:16:07
【问题描述】:
我正在尝试使用从图像中获取的 SIFT 描述符来训练 SVM。然后我想以.xml 格式保存SVM,以便我可以再次加载它。
我的结构:我有 10 个班级,每个班级有 100 个样本。
问题:如果我为每个类使用 10-50 个样本,那么 SVM 将被保存,我可以在我的文件夹中看到一个 classifer.xml 文件。但如果我想使用更多样本,例如每类约 100 个样本,则 SVM 没有得到保存。
我以为它可能需要一些时间才能保存,但我已经等了这么久(我已经做了好几次了)。
我的 SVM 训练代码如下:
void svm::svmTrain()
{
cv::Mat trainme; // it should contain the feature vectors
cv::Mat labels; // it will contain the class labels
createTrainingDateUsingBOW( trainme, labels);
//svm parameters
CvTermCriteria criteria = cvTermCriteria(CV_TERMCRIT_EPS, 1000, FLT_EPSILON);
CvSVMParams svm_params = CvSVMParams (CvSVM::C_SVC, CvSVM::POLY, 10.0 , 8.0 , 1.0 , 10.0 , 0.5 , 0.1 , NULL , criteria); //CvSVMParams --it is a struct
//( svm_type, kernel_type, degree , gamma , coef0 , Cvalue, nu , p , class_weights, term_crit)
cout<<"\n saving SVM \n";
cv::SVM svm;
svm.train(trainme, labels, cv::Mat(), cv::Mat(), svm_params);
svm.save("classifier.xml");
cout<<"\n SVM classifier is saved.";
}
PS: 因此,如果我的样本每班超过 40-60 个,我会从上面的代码中达到 saving SVM,但永远不会达到 SVM classifier is saved.强>
【问题讨论】:
标签: c++ xml opencv filesystems libsvm