将LibSVM输出转换为浮点数向量

我需要形成HOGDescriptor::setSVMDetector()的输入。

我使用openCV计算描述符,然后使用libSVM获取模型文件。为了形成输入,我知道我需要获取支持向量的值,并与alphas进行逐元素乘法(然后在末尾加上-rho),但我不知道从哪里获取这些alphas

我有一份支持向量的列表,如下所示:

1 1:-0.0434783 2:0.153846 3:0.194444 4:-0.353712 5:-0.450541 1:-0.2173916 2:-0.38461 3:0.222262 4:-0.676686 5:-0.78062

但alphas从哪里获取呢?


回答:

好的,现在事情似乎已经清楚了。Alphas是第一列,在我这里是这样。由于我在测试模型中所有的alphas都等于-1或1(不知道为什么),我以为这些是标签。

无论如何,这里是我的解析器(但你需要在文件中只保留SVs):

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设置为检测器的阈值。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注