Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/core/core.hpp>
- #include <opencv2/ml/ml.hpp>
- using namespace cv;
- using namespace std;
- void main(){
- int number_samples = 10400;
- Mat labels(number_samples, 1, CV_32F, Scalar(0));
- int features_length = 206000;
- Mat descriptors(number_samples, features_length, CV_32F, Scalar(0));
- randn(descriptors, 0, 1); //fill with random data
- SVM my_svm;
- SVMParams params;
- params.kernel_type = SVM::LINEAR;
- //This test case will succeed - clear imbalance of positive and negative samples
- labels.rowRange(0, number_samples / 40) = 1;
- try{
- cout << "Training SVM with feature length of: " << features_length << "...";
- my_svm.train(descriptors, labels, Mat(), Mat(), params);
- cout << "Done!" << endl;
- }
- catch (...){
- cout << "Exception ocurred while trying to train SVM" << endl;
- }
- //This test case will fail - same proportion of positive and negative samples
- labels.rowRange(0, number_samples / 2) = 1;
- try{
- cout << "Training SVM with feature length of: " << features_length << "...";
- my_svm.train(descriptors, labels, Mat(), Mat(), params);
- cout << "Done!" << endl;
- }
- catch (...){
- cout << "Exception ocurred while trying to train SVM" << endl;
- }
- //However, this test case will succeed again
- labels.rowRange(0, number_samples / 2) = 1;
- features_length = 205000;
- try{
- cout << "Training SVM with feature length of: " << features_length << "...";
- my_svm.train(descriptors, labels, Mat(), Mat(), params);
- cout << "Done!" << endl;
- }
- catch (...){
- cout << "Exception ocurred while trying to train SVM" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement