Ask Your Question
2

Response is not integral

asked 2013-09-10 11:30:28 -0600

Inneart gravatar image

updated 2013-09-11 23:14:29 -0600

Hi All,

I am solving a multi-class classification problem using C_SVC type. After inputting data into my training_matrix (matrix for data) and training_labels_matrix (matrix for data's labels), I used train_auto to train the SVM.

    Mat training_matrix(TRAINING_ROWS,2,CV_32FC1);
Mat training_label_matrix(TRAINING_ROWS,1,CV_32FC1);

    //Above matrices are filled with data here
    // ....
    // ...

    float weight[3] = {Parameter_C,Parameter_C,Parameter_C};
Mat weights(3,1,CV_32FC1,weight);
CvMat _weight = weights;
CvMat *_weightPtr = &_weight;

//Specify SVM Parameters
CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::RBF;
params.class_weights = _weightPtr;
params.gamma = Gamma;

//Train the SVM
    CvSVM SVM;
SVM.train_auto(training_matrix, training_label_matrix, Mat(), Mat(), params, 1000,
    CvSVM::get_default_grid(CvSVM::C), CvSVM::get_default_grid(CvSVM::GAMMA)); <- Program crashed here

However, the error "OpenCV Error: Bad argument (response #0 is not integral) in cvPreprocessCategoricalResponses, file /opt/local/var/macports/build/_opt_mports_dports_graphics_opencv/opencv/work/opencv-2.4.6/modules/ml/src/inner_functions.cpp, line 715 terminate called throwing an exception(lldb)" comes up and I have no idea how to proceed.

Please help!

Thank you so much...

edit retag flag offensive close merge delete

Comments

Maybe give some code snippets and give a hint where it crashes.

Moster gravatar imageMoster ( 2013-09-10 14:33:55 -0600 )edit

Edited my post to show code snippets. (I have 600 rows of training data and also 600 rows of training data labels)

Inneart gravatar imageInneart ( 2013-09-11 05:56:48 -0600 )edit

Couldnt you try to debug the code and tell us at which line it crashes?

Moster gravatar imageMoster ( 2013-09-12 01:02:13 -0600 )edit

Hi, the program crashed at SVM.train_auto(training_matrix, training_label_matrix, Mat(), Mat(), params, 1000,CvSVM::get_default_grid(CvSVM::C), CvSVM::get_default_grid(CvSVM::GAMMA));

Inneart gravatar imageInneart ( 2013-09-12 11:29:30 -0600 )edit

I have the same trouble, and I have no idea what should I do to fix this bug. Hope someone can help :D

tuhoang gravatar imagetuhoang ( 2014-01-08 12:14:48 -0600 )edit

I am getting this error if I save a SVM, then try to load it and keep training on it. Is this not possible?

ejehardenberg gravatar imageejehardenberg ( 2014-10-01 13:20:48 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-09-12 14:04:36 -0600

Moster gravatar image

Ok, I stepped through the source code and found the error.

 for( i = 0; i < sample_count; i++ )
{
    int idx = map ? map[i] : i;
    assert( (unsigned)idx < (unsigned)sample_all );
    if( r_type == CV_32SC1 )
        dst[i] = srci[idx*r_step];
    else
    {
        float rf = srcfl[idx*r_step];
        int ri = cvRound(rf);
        if( ri != rf )
        {
            char buf[100];
            sprintf( buf, "response #%d is not integral", idx );
            CV_ERROR( CV_StsBadArg, buf );
        }
        dst[i] = ri;
    }
    response_ptr[i] = dst + i;
}

What I find kind of strange is that they get a float value float rf = srcfl[idx*r_step], then round it to an int and then compare the int and the float. I mean, float and int comparison in general is not good. Im not sure if this is a bug or supposed to be like that. If your training_label_matrix was of type CV_32SC1 you wouldnt have that issue, but I dont know if thats even useful. Im not familiar with machine learning.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-09-10 11:30:28 -0600

Seen: 1,780 times

Last updated: Sep 12 '13