参考资料:
https://docs.opencv.org/master/d1/d2d/classcv_1_1ml_1_1SVM.html#ab4b93a4c42bbe213ffd9fb3832c6c44f
http://read.pudn.com/downloads535/doc/fileformat/2211295/libsvm.pdf
关于参数调试及优化:
1.关于调参的参数介绍
本次模型训练优化并没有测试所有SVM相关参数以及设置,所以结果可能有待提高,但是在改进范围内已经是最优结果。
核函数选择: RBF核函数;
特征选择: “DenseNet” or “eGemaps” or “LBPTOP”,本次并没有选择"HOG"特征,并且把剩下三种特征进行两两组合,以及三种特征融合;
标签选择: 数据集中有0.55和0.65,因为时间关系只选择了0.65进行测试;
评价指标: 分类总正确率简称PCC,是英文Percentage correct classification的缩写。它被定义为分类统计频率矩阵P的主对角线元素之和。
详细解释: https://blog.csdn.net/wyl1813240346/article/details/56843409
训练类型: 在opencv-svm中的类型一共五种:C_SVC、NU_SVC、ONE_CLASS、EPS_SVR、NU_SVR,这里选择EPS_SVR和NU_SVR两种分别调试:
//EPS_SVR类型的设置
void SVMEmotion::train(cv::Mat train_mat, cv::Mat label_mat, float C_value, float G_value, float epsilon) {
cv::Ptr<cv::ml::SVM> svm = cv::ml::SVM::create();
svm->setType(cv::ml::SVM::EPS_SVR); // EPSILON_SVR; // do regression task
svm->setKernel(cv::ml::SVM::RBF); // or linear
svm->setP(epsilon); // for EPS_SVR, which has epsilon in loss function (0.1)
svm->setC(C_value); // penality value (32)
svm->setGamma(G_value); // for kernel funs (1)
svm->setTermCriteria(cv::TermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 1000, 1e-5)); // max_iter:100 stop when the loss is less than 1e-3
svm->train(train_mat, cv::ml::ROW_SAMPLE, label_mat);
svm->save("svm.xml");
cout << "训练结束" << endl;
}
//NU_SVR类型的设置
void SVMEmotion::train(cv::Mat train_mat, cv::Mat label_mat, float C_value, float G_value, float nu) {
cv::Ptr<cv::ml::SVM> svm = cv::ml::SVM::create();
svm->setType(cv::ml::SVM::NU_SVR); // nu_SVR; // do regression task
svm->setKernel(cv::ml::SVM::RBF); // or linear
svm->setNu(nu); // for NU_SVR
svm->setC(C_value); // penality value (32)
svm->setGamma(G_value); // for kernel funs (1)
svm->setTermCriteria(cv::TermCriteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 1000, 1e-5)); // max_iter:100 stop when the loss is less than 1e-3
svm->train(train_mat, cv::ml::ROW_SAMPLE, label_mat);
svm->save("svm.xml");
cout << "训练结束" << endl;
}
三种参数调参: 相关代码如下
vector<float> best_configs(3, 0.0);
for (int ii = 24; ii <= 50; ii++) {
for (int jj = 24; jj <= 50; jj++) {
for (int kk = 1; kk <= 100; kk=kk+5) {
float C_value = pow(2, ii); // params 1//目前这个参数不是最优//C惩罚系数
float G_value = pow(2, jj); // params 2//目前这个参数不是最优//G核函数半径
float epsilon = kk*0.001; // params 3//EPS_SVR//一般选择epsilon=5e-3
//float nu = kk*0.001; // params 3//NU_SVR
// training
svmemotion.train(train_dataLabels[0], train_dataLabels[1], C_value, G_value, epsilon);//此处为EPS_SVR//NU_SVR的话就把epsilon改成nu
// testing
cv::Mat train_predictedResults = svmemotion.predict(train_dataLabels[0]);
cv::Mat test_predictedResults = svmemotion.predict(test_dataLabels[0]);
// calcu pcc
float train_PCC = svmemotion.PCC(train_dataLabels[1], train_predictedResults);
float test_PCC = svmemotion.PCC(test_dataLabels[1], test_predictedResults);
// find the max PCC
if (test_PCC > best_test_PCC) {
best_test_PCC = test_PCC;
best_configs[0] = C_value;
best_configs[1] = G_value;
best_configs[2] = epsilon;//此处为EPS_SVR//NU_SVR的话就把epsilon改成nu
}
// print results
fout << "#######################" << endl;
fout << "C_value: " << C_value << endl;
fout << "G_value: " << G_value << endl;
fout << "epsilon: " << epsilon << endl;//此处为EPS_SVR//NU_SVR的话就把epsilon改成nu
fout << "train_PCC: " << train_PCC << endl;
fout << "test_PCC: " << test_PCC << endl;
fout << "best_test_PCC: " << best_test_PCC << endl;
fout << "best_test_PCC_config1: " << best_configs[0] << endl;
fout << "best_test_PCC_config1: " << best_configs[1] << endl;
fout << "best_test_PCC_config1: " << best_configs[2] << endl;
fout << "#######################" << endl;
}
}
}
因为PCC指标分为了评价值(Valence)和唤起程度(Arousal)两种,分别进行了测试。
///
/
/
/
/
//
/
/
/
/
/
标签选择0.65,计算SVM的PCC指标:
PCC | arousal | valence | |
---|---|---|---|
DenseNet | 0.348901(EPS) | 0.604435(EPS) | |
eGemaps | 0.578969(EPS) | 0.18071(EPS) | |
LBPTOP | 0.239847(EPS) | —— | |
DenseNet + eGemaps | 0.602442 | 0.698954 | |
DenseNet + LBPTOP | 0.0973741 | —— | |
eGemaps + LBPTOP | 0.107387 | —— | |
DenseNet + eGemaps + LBPTOP | 0.0216067 | —— | |
start processing on DenseNet
#######################
C_value: 3.35544e+07
G_value: 3.35544e+07
epsilon: 0.096
train_PCC: 0.939915
test_PCC: -1.79211e-06
best_test_PCC: 0.348901
best_test_PCC_config1: 0.25
best_test_PCC_config1: 16
best_test_PCC_config1: 0.056
#######################
start processing on eGemaps
#######################
C_value: 0.5
G_value: 3.05176e-05
epsilon: 0.2
train_PCC: 0.72442
test_PCC: 0.498364
best_test_PCC: 0.578969
best_test_PCC_config1: 0.25
best_test_PCC_config1: 3.8147e-06
best_test_PCC_config1: 0.055
#######################
start processing on LBPTOP
#######################
C_value: 0.25
G_value: 8
epsilon: 0.0096
train_PCC: 0.827096
test_PCC: 0.214694
best_test_PCC: 0.239847
best_test_PCC_config1: 0.125
best_test_PCC_config1: 4
best_test_PCC_config1: 0.0026
#######################
start processing on DenseNet_eGemaps
#######################
C_value: 0.25
G_value: 16
epsilon: 0.06
train_PCC: 0.946594
test_PCC: 0.244773
best_test_PCC: 0.602442
best_test_PCC_config1: 0.25
best_test_PCC_config1: 4
best_test_PCC_config1: 0.008
#######################
start processing on LBPTOP_eGemaps
#######################
C_value: 0.25
G_value: 16
epsilon: 0.06
train_PCC: 0.958878
test_PCC: 0.0783875
best_test_PCC: 0.107387
best_test_PCC_config1: 0.25
best_test_PCC_config1: 4
best_test_PCC_config1: 0.024
#######################
start processing on DenseNet_LBPTOP
#######################
C_value: 0.25
G_value: 16
epsilon: 0.044
train_PCC: 0.956527
test_PCC: 0.0932308
best_test_PCC: 0.0973741
best_test_PCC_config1: 0.125
best_test_PCC_config1: 8
best_test_PCC_config1: 0.054
#######################
DenseNet + eGemaps + LBPTOP
#######################
C_value: 0.25
G_value: 4
epsilon: 0.026
train_PCC: 0.955805
test_PCC: 0.021606
best_test_PCC: 0.0216067
best_test_PCC_config1: 0.25
best_test_PCC_config1: 4
best_test_PCC_config1: 0.002
#######################
标签选择0.55,计算SVM的PCC指标:
PCC | arousal | valence | |
---|---|---|---|
DenseNet | 0.0.314449(EPS) | 0.602884(EPS) | |
eGemaps | 0.483838(EPS) | 0.232211(EPS) | |
LBPTOP | 0. 204178(EPS) | —— | |
DenseNet + eGemaps | 0.598922 | 0.687386 | |
DenseNet + LBPTOP | 0.364655 | —— | |
eGemaps + LBPTOP | 0.102169 | —— | |
DenseNet + eGemaps + LBPTOP | 0.0996446 | —— | |
start processing on DenseNet
#######################
C_value: 0.5
G_value: 32
epsilon: 0.096
train_PCC: 0.267932
test_PCC: 0.11849
best_test_PCC: 0.314449
best_test_PCC_config1: 0.5
best_test_PCC_config1: 16
best_test_PCC_config1: 0.031
#######################
eGemaps
#######################
C_value: 0.25
G_value: 7.62939e-06
epsilon: 9.6e-06
train_PCC: 0.558431
test_PCC: 0.463776
best_test_PCC: 0.483838
best_test_PCC_config1: 0.25
best_test_PCC_config1: 1.90735e-06
best_test_PCC_config1: 9.1e-06
#######################
LBP
#######################
C_value: 0.25
G_value: 8
epsilon: 0.051
train_PCC: 0.806014
test_PCC: 0.181722
best_test_PCC: 0.204178
best_test_PCC_config1: 0.125
best_test_PCC_config1: 4
best_test_PCC_config1: 0.016
#######################
normalization approach minmax
start processing on DenseNet_eGemaps
#######################
C_value: 0.25
G_value: 4
epsilon: 0.008
train_PCC: 0.941638
test_PCC: 0.602442
best_test_PCC: 0.602442
best_test_PCC_config1: 0.25
best_test_PCC_config1: 4
best_test_PCC_config1: 0.008
#######################
start processing on DenseNet_LBPTOP
#######################
C_value: 0.25
G_value: 4
epsilon: 0.008
train_PCC: 0.786106
test_PCC: 0.364655
best_test_PCC: 0.364655
best_test_PCC_config1: 0.25
best_test_PCC_config1: 4
best_test_PCC_config1: 0.008
#######################
start processing on LBPTOP_eGemaps
#######################
C_value: 0.25
G_value: 4
epsilon: 0.008
train_PCC: 0.955245
test_PCC: 0.102169
best_test_PCC: 0.102169
best_test_PCC_config1: 0.25
best_test_PCC_config1: 4
best_test_PCC_config1: 0.008
#######################
start processing on DenseNet_LBPTOP_eGemaps
#######################
C_value: 0.25
G_value: 4
epsilon: 0.008
train_PCC: 0.955259
test_PCC: 0.0996446
best_test_PCC: 0.0996446
best_test_PCC_config1: 0.25
best_test_PCC_config1: 4
best_test_PCC_config1: 0.008
#######################