TrainSVM convert_to_ml error

asked 2015-08-25 18:09:31 -0600

Bbop gravatar image

updated 2018-09-06 13:20:05 -0600

Hi,

I am attempting to train the defaultPeopleDetctor for the HOG person C++ example. I get an out of memory error at the convert_to_ml stage.

/*
* Convert training/testing set to be used by OpenCV Machine Learning algorithms.
* TrainData is a matrix of size (#samples x max(#cols,#rows) per samples), in 32FC1.
* Transposition of samples are made if needed.
*/
void convert_to_ml(const std::vector< cv::Mat > & train_samples, cv::Mat& trainData)
{
    //--Convert data
    const int rows = (int)train_samples.size();
    const int cols = (int)std::max(train_samples[0].cols, train_samples[0].rows);
    cv::Mat tmp(1, cols, CV_32FC1); //< used for transposition if needed
    trainData = cv::Mat(rows, cols, CV_32FC1);
    vector< Mat >::const_iterator itr = train_samples.begin();
    vector< Mat >::const_iterator end = train_samples.end();
    for (int i = 0; itr != end; ++itr, ++i)
    {
        CV_Assert(itr->cols == 1 ||
            itr->rows == 1);
        if (itr->cols == 1)
        {
            transpose(*(itr), tmp);
            tmp.copyTo(trainData.row(i));
        }
        else if (itr->rows == 1)
        {
            itr->copyTo(trainData.row(i));
        }
    }
}

Does anyone know why this would occur? I'm using the INRIA person data set for training.

edit retag flag offensive close merge delete

Comments

1

First of all, do not duplicate posts. And now, the out of memory error arises because your system does not have enough RAM memory to allocate all the required data. How much RAM does your computer have?

LorenaGdL gravatar imageLorenaGdL ( 2015-08-26 03:35:51 -0600 )edit

you probably could try to avoid the vector<Mat> , and copy to your trainData when loading images.

berak gravatar imageberak ( 2015-08-26 03:53:19 -0600 )edit

Sorry I'm a noob. It was a dumb mistake, I didn't check the resolution of the positive samples, which caused it to use this amount of memory. I have 24GB.

Bbop gravatar imageBbop ( 2015-08-26 23:25:39 -0600 )edit