我需要形成HOGDescriptor::setSVMDetector()
input.
我使用 openCV 计算描述符,然后使用 libSVM 获取模型文件。
为了形成输入,我知道我需要获取支持向量的值并将它们与 alpha 进行元素相乘(然后在末尾添加 -rho),但是我不知道从哪里得到这些阿尔法.
我有一个 SV 列表,例如:
1 1:-0.0434783 2:0.153846 3:0.194444 4:-0.353712 5:-0.45054
1 1:-0.2173916 2:-0.38461 3:0.222262 4:-0.676686 5:-0.78062
但是哪里可以获得阿尔法呢?
好吧,现在看来事情已经清楚了。Alpha 是第一列就我而言。
因为我的测试模型中所有这些都等于 -1 或 1(不知道为什么),所以我认为这些是标签。
无论如何,这是我的解析器(但你只需要在文件中保留 SV):
std::ifstream ifs("cars_model.model");
const int nsv = 90;
const int nfeatures = 144;
float rho = 12.5459;
char ts[4000] = ""; // !
std::vector<float> res(nfeatures,0);
std::vector<float> alphas;
Mat_<float> temp(nsv, nfeatures);
int c = 0;
std::cout << "Loading model file...\n";
for (int i=0; i<nsv; i++) {
float al = 0;
ifs >> al;
alphas.push_back(al);
for (int j=0; j<nfeatures; j++) {
float ind, s;
char junk;
ifs >> ind >> junk >> s;
temp.at<float>(c, j) = s;
//std::cout << f << ' ' << s << '\n';
}
c++;
}
ifs.close();
std::cout << "Computing primal form...\n";
for (int i=0; i<nsv; i++) {
float alpha = alphas[i];
for (int j=0; j<nfeatures; j++) {
res[j] += (temp.at<float>(i,j) * alpha);
}
}
//res.push_back(-rho);
std::ofstream ofs("primal.txt");
for (int i=0; i<res.size(); i++)
ofs << res[i] << ' ';
ofs.close();
你知道,它有效。您可以将 rho 设置为检测器的阈值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)