Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Bad argument on classification problem

Hello guys, I'm trying to compile this code having ONLY 1 LABEL fro object classification (I know it may seems like it doesn't make sense, but one label is just what I need). While compiling this code:

    Ptr<SIFT> detector = SIFT::create(); //detector to detect SIFT features 


Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::FLANNBASED);

BOWImgDescriptorExtractor bowDE(detector, matcher);
bowDE.setVocabulary(dictionary);


cout << "extracting histograms in the form of BOW for each Training image " << endl;
int label[1] = {1};
Mat labels(0, 1, CV_32FC1, label);
int dictSize = 1500;

float trainingData1[2][2] = { { 501, 10 }, { 255, 10 } };
Mat trainingData(0, dictSize, CV_32FC1, trainingData1);
int k = 0;
vector<KeyPoint> keypoint;
Mat bowDescriptor;
Mat img;

vector<String> fn;
vector<Mat> data;
glob("C:/Users/albma/Desktop/Università/Computer Vision/Final_Project/Nonmio/train/*.jpg", fn, true);

//extracting histogram in the form of bow for each image
    for (size_t i = 0; i < fn.size(); i++) { //each class having 60 images

        printf("Training Image = %s\n", fn[i]);
        img = imread(fn[i], 0);
        detector->detect(img, keypoint); //detect keypoints
        bowDE.compute(img, keypoint, bowDescriptor); //compute descriptors
        trainingData.push_back(bowDescriptor);
        labels.push_back((float)1); //push labels in a matrix.. 1,2,3,4
    }


//SVM Part

Ptr<SVM> svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));



printf("Training SVM\n");
Ptr<TrainData> td = TrainData::create(trainingData, ROW_SAMPLE, labels); //start training SVM
svm->train(td);

I get this error: Bad argument (in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses). What should I fix? Thanks everyone!

Bad argument on classification problem

Hello guys, I'm trying to compile this code having ONLY 1 LABEL fro object classification (I know it may seems like it doesn't make sense, but one label is just what I need). While compiling this code:

    Ptr<SIFT> detector = SIFT::create(); //detector to detect SIFT features 


Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::FLANNBASED);

BOWImgDescriptorExtractor bowDE(detector, matcher);
bowDE.setVocabulary(dictionary);


cout << "extracting histograms in the form of BOW for each Training image " << endl;
int label[1] = {1};
Mat labels(0, 1, CV_32FC1, label);
int dictSize = 1500;

float trainingData1[2][2] = { { 501, 10 }, { 255, 10 } };
Mat trainingData(0, dictSize, CV_32FC1, trainingData1);
int k = 0;
vector<KeyPoint> keypoint;
Mat bowDescriptor;
Mat img;

vector<String> fn;
vector<Mat> data;
glob("C:/Users/albma/Desktop/Università/Computer Vision/Final_Project/Nonmio/train/*.jpg", fn, true);

//extracting histogram in the form of bow for each image
    for (size_t i = 0; i < fn.size(); i++) { //each class having 60 images
//for each image

        printf("Training Image = %s\n", fn[i]);
        img = imread(fn[i], 0);
        detector->detect(img, keypoint); //detect keypoints
        bowDE.compute(img, keypoint, bowDescriptor); //compute descriptors
        trainingData.push_back(bowDescriptor);
        labels.push_back((float)1); //push labels in a matrix.. 1,2,3,4
1
    }


//SVM Part

Ptr<SVM> svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));



printf("Training SVM\n");
Ptr<TrainData> td = TrainData::create(trainingData, ROW_SAMPLE, labels); //start training SVM
svm->train(td);

I get this error: Bad argument (in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses). What should I fix? Thanks everyone!

Bad argument on classification problem

Hello guys, I'm trying to compile this code having ONLY 1 LABEL fro object classification (I know it may seems like it doesn't make sense, but one label is just what I need). While compiling this code:

    Ptr<SIFT> detector = SIFT::create(); //detector to detect SIFT features 


Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::FLANNBASED);

BOWImgDescriptorExtractor bowDE(detector, matcher);
bowDE.setVocabulary(dictionary);


cout << "extracting histograms in the form of BOW for each Training image " << endl;
int label[1] = {1};
 Mat labels(0, 1, CV_32FC1, label);
CV_32S);
int dictSize = 1500;

float trainingData1[2][2] = { { 501, 10 }, { 255, 10 } };
Mat trainingData(0, dictSize, CV_32FC1, trainingData1);
CV_32FC1);
int k = 0;
vector<KeyPoint> keypoint;
Mat bowDescriptor;
Mat img;

vector<String> fn;
vector<Mat> data;
glob("C:/Users/albma/Desktop/Università/Computer Vision/Final_Project/Nonmio/train/*.jpg", fn, true);

//extracting histogram in the form of bow for each image
    for (size_t i = 0; i < fn.size(); i++) { //for each image

        printf("Training Image = %s\n", fn[i]);
        img = imread(fn[i], 0);
        detector->detect(img, keypoint); //detect keypoints
        bowDE.compute(img, keypoint, bowDescriptor); //compute descriptors
        trainingData.push_back(bowDescriptor);
        labels.push_back((float)1); //push labels in a matrix.. 1
    }


//SVM Part

Ptr<SVM> svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));



printf("Training SVM\n");
Ptr<TrainData> td = TrainData::create(trainingData, ROW_SAMPLE, labels); //start training SVM
svm->train(td);

I get this error: Bad argument (in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses). What should I fix? Thanks everyone!

Bad argument on classification problem

Hello guys, I'm trying to compile this code having ONLY 1 LABEL fro object classification (I know it may seems like it doesn't make sense, but one label is just what I need). While compiling this code:

    Ptr<SIFT> detector = SIFT::create(); //detector to detect SIFT features 


Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::FLANNBASED);

BOWImgDescriptorExtractor bowDE(detector, matcher);
bowDE.setVocabulary(dictionary);


cout << "extracting histograms in the form of BOW for each Training image " << endl;

Mat labels(0, 1, CV_32S);
int dictSize = 1500;

Mat trainingData(0, dictSize, CV_32FC1);
CV_32S);
int k = 0;
vector<KeyPoint> keypoint;
Mat bowDescriptor;
Mat img;

vector<String> fn;
vector<Mat> data;
glob("C:/Users/albma/Desktop/Università/Computer Vision/Final_Project/Nonmio/train/*.jpg", fn, true);

//extracting histogram in the form of bow for each image
    for (size_t i = 0; i < fn.size(); i++) { //for each image

        printf("Training Image = %s\n", fn[i]);
        img = imread(fn[i], 0);
        detector->detect(img, keypoint); //detect keypoints
        bowDE.compute(img, keypoint, bowDescriptor); //compute descriptors
        trainingData.push_back(bowDescriptor);
        labels.push_back((float)1); //push labels in a matrix.. 1
    }


//SVM Part

Ptr<SVM> svm = SVM::create();
svm->setType(SVM::C_SVC);
svm->setKernel(SVM::LINEAR);
svm->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER, 100, 1e-6));



printf("Training SVM\n");
Ptr<TrainData> td = TrainData::create(trainingData, ROW_SAMPLE, labels); //start training SVM
svm->train(td);

I get this error: Bad argument (in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses). What should I fix? Thanks everyone!