Ask Your Question

Hadi's profile - activity

2015-03-26 14:23:40 -0600 received badge  Student (source)
2015-03-01 18:31:52 -0600 received badge  Enthusiast
2015-02-27 03:30:34 -0600 commented answer Neural Network calling classifier

https://www.dropbox.com/s/vz3t66vsc22... Here is the link to the param.xml file its around 1.8 MB

2015-02-26 18:16:05 -0600 commented answer Neural Network calling classifier

Its going inside the load function but not coming out of it. I have updated the question where it is exiting please see. Thank you

2015-02-25 18:49:22 -0600 asked a question Neural Network calling classifier

Hi, I trained one classifier for OCR testing using RPROP method but when i am trying to load the trained parameter file it is exiting the code without any error.

cv::String file_name = "C:\\Users\\param.xml";
ANN_MLP *nnetwork;

nnetwork->load<ANN_MLP>(file_name);

Is the call for the network correct ? Please help me out here. Thank you.

EDIT 1:

The function is exiting while checking for mapping in this code

 if( !CV_NODE_IS_MAP(map_node->tag) )
 {
      if( (!CV_NODE_IS_SEQ(map_node->tag) || map_node->data.seq->total != 0) &&
           CV_NODE_TYPE(map_node->tag) != CV_NODE_NONE )
           CV_Error( CV_StsError, "The node is neither a map nor an empty collection" );
       return 0;
 }

I checked the name of the node and its the same but it is still unable to map it correctly.

I used the following method to save the parameter file pelase see

FileStorage fs("C:\\Users\\param.xml", FileStorage::WRITE);
classifier->write(fs);
fs.release();
2015-02-25 18:15:26 -0600 commented question Neural network with 3.0.0

I have updated the question with the call please check. Thank you

2015-02-25 18:14:59 -0600 received badge  Editor (source)
2015-02-24 21:30:59 -0600 asked a question Neural network with 3.0.0

Hi, I am pretty new to neural networks in opencv. I read through the documentation and this is how i have implemented the training of the network

cv::Ptr<cv::ml::ANN_MLP> classifier = cv::ml::ANN_MLP::create();


ANN_MLP::Params params;
params.activateFunc = ANN_MLP::SIGMOID_SYM;
params.layerSizes = layers;
params.fparam1 = 0.6;
params.fparam2 = 1;
params.termCrit = TermCriteria(cv::TermCriteria::MAX_ITER+cv::TermCriteria::EPS, 1000, 0.000001);
params.trainMethod = ANN_MLP::Params::BACKPROP;
params.bpDWScale = 0.1;
params.bpMomentScale = 0.1;
params.rpDW0 = 0.1; 
params.rpDWPlus = 1.2; 
params.rpDWMinus = 0.5;
params.rpDWMin = FLT_EPSILON; 
params.rpDWMax = 50.;




classifier->setParams(params);

int iterations = classifier->train(training_set,ROW_SAMPLE,training_set_classifications);


FileStorage fs("C:\\Users\\Hadi\\Downloads\\output\\param.xml", FileStorage::WRITE);

classifier->write(fs);
fs.release();

But on running of the code it is giving me abort error on training part. It is saying something like:

Expression Error : Vector subscript out of range

Can anybody please guide me to some tutorial for training and predicting of neural networks using opencv 3.0. Thank you.

EDIT 1:

I am setting up the layers as follows :

 cv::Mat layers(3,1,CV_32S);
layers.at<int>(0,0) = ATTRIBUTES;//input layer
layers.at<int>(1,0) = ATTRIBUTES;//hidden layer
layers.at<int>(2,0) = CLASSES;//output layer

and reading the data from txt files with the following function :

void read_dataset(char *filename, cv::Mat &data, cv::Mat &classes,  int total_samples)
{
    int label;
    float pixelvalue;
    //open the file
    FILE* inputfile = fopen( filename, "r" );

    //read each row of the csv file
   for(int row = 0; row < total_samples; row++)
   {
       //for each attribute in the row
     for(int col = 0; col <=ATTRIBUTES; col++)
        {
            //if its the pixel value.
            if (col < ATTRIBUTES){

                fscanf(inputfile, "%f,", &pixelvalue);
                data.at<float>(row,col) = pixelvalue;

            }//if its the label
            else if (col == ATTRIBUTES){
                //make the value of label column in that row as 1.
                fscanf(inputfile, "%i", &label);
                classes.at<float>(row,label) = 1.0;

            }
        }
    }

    fclose(inputfile);
}

The call is as follows :

cv::Mat test_set_classifications(TEST_SAMPLES,CLASSES,CV_32F);

cv::Mat classificationResult(1, CLASSES, CV_32F);
//load the training and test data sets.
read_dataset("C:\\Users\\Hadi\\Downloads\\output\\trainingset.txt", training_set, training_set_classifications, TRAINING_SAMPLES);
read_dataset("C:\\Users\\Hadi\\Downloads\\output\\testset.txt", test_set, test_set_classifications, TEST_SAMPLES);

I further checked the functions and the error is generating on this line

x[i-1][n1] = 1.;

in the loop for train_backprop( const Mat& inputs, const Mat& outputs, const Mat& _sw, TermCriteria termCrit )

       // backward pass, update weights
        for( i = l_count-1; i > 0; i-- )
        {
            int n1 = layer_sizes[i-1], n2 = layer_sizes[i];
            Mat _df(1, n2, CV_64F, &df[i][0]);
            multiply( grad1, _df, grad1 );
            Mat _x(n1+1, 1, CV_64F, &x[i-1][0]);
            x[i-1][n1] = 1.;
            gemm( _x, grad1, params.bpDWScale, dw[i], params.bpMomentScale, dw[i] );
            add( weights[i], dw[i], weights[i] );
            if( i > 1 )
            {
                Mat grad2(1, n1, CV_64F, buf[i&1]);
                Mat _w = weights[i].rowRange(0, n1);
                gemm( grad1, _w, 1, noArray(), 0, grad2, GEMM_2_T );
                grad1 = grad2;
            }
        }

P.S : The method is working for RPROP but not for BACKPROP.