SVM培训时间是否取决于输入数据的内容?

时间:2017-07-09 19:45:38

标签: c++ opencv svm

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

两次我都使用相同的参数: C = 0.01,1.00000次迭代,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;
}

1 个答案:

答案 0 :(得分:3)

这不可能。

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

相关问题