负载训练的SVM – Emgu CV [英] Load Trained SVM – Emgu CV
问题描述
我对SVM和对象识别有些陌生,目前正在尝试使用Emgu CV 3.0训练SVM,将其保存到文件中,然后加载(在HOGDescriptor.SetSVMDetector中使用).
I am somewhat new to SVMs and object recognition, and am currently attempting to train an SVM using Emgu CV 3.0, save it to a file, and then load it (for use in HOGDescriptor.SetSVMDetector).
但是,除其他问题外,保存后我无法找到加载SVM的方法.
However, among other problems, I cannot find a way to load the SVM after I have saved it.
到目前为止,我的代码基本上执行以下操作:
So far, my code basically does the following:
SVM myFirstSVM = new SVM();
// do some stuff, set some parameters...
myFirstSVM.Train(someParameters);
myFirstSVM.Save("filePath");
从这里开始,问题出在保存后重新加载 SVM.我检查了几个帮助主题和页面,发现的唯一相关内容与OpenCV有关,它使用以下方法:
From here, the problem lies with reloading the SVM after being saved. I have checked several help topics and pages, and the only related things I could find pertained to OpenCV, which used the following method:
SVM mySecondSVM;
mySecondSVM.load("filePath");
但是,尽管在以前的版本中似乎没有提供方法".load()",但在Emgu 3.0中却找不到该方法. Emgu 3.0中是否有与此OpenCV方法等效的方法?我以为有,而且我相信它很简单,但是我一生都找不到.
However, I could find no method ".load()" in Emgu 3.0, although it appeared to be present in previous versions. Is there an equivalent of this OpenCV method in Emgu 3.0? I would assume there is, and I am sure it is fairly simple, but I cannot for the life of me find it.
推荐答案
对于EmguCV 3.0.0,似乎不支持Save/Load
功能(Load
不存在),可以使用
For EmguCV 3.0.0, the Save/Load
functionality doesn't seem to be supported (Load
doesn't exist), you could use Write/Read
instead.
保存SVM模型的功能:
A function to save an SVM model:
public static void SaveSVMToFile(SVM model, String path) {
if (File.Exists(path)) File.Delete(path);
FileStorage fs = new FileStorage(path, FileStorage.Mode.Write);
model.Write(fs);
fs.ReleaseAndGetString();
}
用于加载SVM模型的函数提供了正确的路径:
A function to load the SVM model provided the correct path:
public static SVM LoadSVMFromFile(String path) {
SVM svm = new SVM();
FileStorage fs = new FileStorage(path, FileStorage.Mode.Read);
svm.Read(fs.GetRoot());
fs.ReleaseAndGetString();
return svm;
}
这篇关于负载训练的SVM – Emgu CV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!