【问题标题】:Does SVM training time depend on content of input data?SVM 训练时间是否取决于输入数据的内容?
【发布时间】:2017-12-13 11:56:53
【问题描述】:

我正在训练一个 SVM(来自 opencv 的 train_auto)两次。

两次我都使用相同的参数: C=0.01,100.000 次迭代,32 个特征和 24550 个样本。 但是不同的输入样本。第一次我只使用我的训练数据,第二次,更少的训练数据+一些假阴性,但训练数据量与第一步完全相同。

第一次训练在大约 2 小时后结束。而第二次运行无休止(超过 10 小时)。这怎么可能?我该如何解决这个问题?

您好, 斯特菲

编辑一些代码:

void SVMtrain(bool retraining) {

    int factor_pos = 5;
    int factor_neg = 10;

    std::string line;
    int N_pos = 2474;
    N_pos *= factor_pos;

    int N_neg = 0;
    std::ifstream myfile2(LIST_NEG);
    while (std::getline(myfile2, line))
        ++N_neg;
    N_neg *= factor_neg;

    Mat points = createFirstSet(N_pos, N_neg, factor_pos, factor_neg);
    Mat labels = createFirstLabels(N_pos, N_neg);

    Mat all_neg;
    if (retraining) {
        Mat hardNegatives = find_hardNegatives();
        hardNegatives.copyTo(points(Rect(0, points.rows - (MAX_HARD_NEG+1), hardNegatives.cols, hardNegatives.rows)));
    }

    // Train with SVM
    CvSVMParams params;
    params.svm_type = CvSVM::C_SVC;
    params.kernel_type = CvSVM::LINEAR;
    params.C = 0.01; //best option according to Dalal and Triggs
    params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, iterations, 1e-6);


    CvSVM SVM;
    if (retraining) {
        cout << "Training SVM with " << points.rows << " Datapoints... (" << N_pos << ", " << points.rows - N_pos << ") since: " << getTimeFormatted()<< endl;
        SVM.train_auto(points, labels, Mat(), Mat(), params);
        SVM.save(SVM_2_LOCATION);
    }
    else {
        cout << "Training SVM with " << points.rows << " Datapoints... (" << N_pos << ", " << N_neg << ") since: " << getTimeFormatted() << endl;
        SVM.train_auto(points, labels, Mat(), Mat(), params);
        SVM.save(SVM_LOCATION);
    }
    cout << "finished training at " << getTimeFormatted() << endl << endl;
}

【问题讨论】:

  • 如果您认为数据不是线性可分的,我建议您尝试使用 RBF 内核。此外,您可以尝试组合标志,例如:迭代 + EPS。
  • 但是 RBF 通常比线性花费更长的时间,不是吗?但是我会尝试。谢谢你的提示。

标签: c++ opencv svm


【解决方案1】:

这应该是不可能的。

但是你提到,在第二次训练中你添加了一些假阴性。虽然我不确切知道您的数据是什么样的,但我假设这使得数据不是线性可分的。这可能会破坏您对 SVM 的实施。否则我帮不了你

【讨论】:

  • 感谢您的回答。我正在使用 SVM 进行 64x128 HoG 单元的行人检测。所以第一次训练不应该是线性可分的,我猜?
猜你喜欢
  • 2014-05-18
  • 2017-07-29
  • 2015-09-26
  • 2016-08-09
  • 2015-08-14
  • 2015-06-24
  • 2018-08-04
  • 2014-11-03
  • 2019-07-12
相关资源
最近更新 更多