OpenCV several objects CvANN_MLP

asked 2014-01-04 04:06:00 -0600

sploid gravatar image

I am writing an application for ANPR. Is part of the neural network training: https://github.com/sploid/plate_recognition/blob/recog_sym_by_nn/train_neural_network/main.cpp

  • line 246 : training chars
  • line 247 : training numbers

If I interchange the line, I get different results. I do not have static variables and all variables are created on the stack. Why am I getting these strange results?

edit retag flag offensive close merge delete

Comments

what is your 'strange result' ?

berak gravatar imageberak ( 2014-01-04 04:20:26 -0600 )edit

In code: FileStorage fs( path_to_save_train( module_path, num ), cv::FileStorage::WRITE ); mlp.write( *fs, "mlp" ); I save network state in file, and the result of training is different.

sploid gravatar imagesploid ( 2014-01-04 05:05:22 -0600 )edit

you expect us to debug your github repo ?

berak gravatar imageberak ( 2014-01-04 05:28:38 -0600 )edit

I expect to hear something that is not in the documentation. Something like this answer: http://answers.opencv.org/question/25965/opencv-neural-networks/

sploid gravatar imagesploid ( 2014-01-04 05:36:57 -0600 )edit
1

I made a very simple example:

Mat first_size( 1, 2, CV_32SC1 );
first_size.at< int >( 0 ) = data_width * data_height;
first_size.at< int >( 1 ) = 12;

{
    CvANN_MLP mlp1( first_size );
    const int rrr = mlp1.train( input, output, weights );
    FileStorage fs( "C:\\imgs\\t0.yml", cv::FileStorage::WRITE);
    mlp1.write(*fs, "mlp");
}
{
    CvANN_MLP mlp2( first_size );
    const int rrr = mlp2.train( input, output, weights );
    FileStorage fs( "C:\\imgs\\t1.yml", cv::FileStorage::WRITE);
    mlp2.write(*fs, "mlp");
}

weights in t1.yml t2.yml are different!!!! Why?

sploid gravatar imagesploid ( 2014-01-04 06:12:46 -0600 )edit
1

I found the reason. same post: https://code.ros.org/trac/opencv/ticket/1411 Reason difference in random generator.

sploid gravatar imagesploid ( 2014-01-04 07:26:57 -0600 )edit

the rng used is the global cv::theRNG()

you could try to seed it to the same val in each run

berak gravatar imageberak ( 2014-01-04 08:26:51 -0600 )edit
1

I harcode everywhere:

theRNG().state = 0x111111; CvANN_MLP mlp( ... ); mlp.train( input, output, weights );

and OK.

sploid gravatar imagesploid ( 2014-01-04 08:34:34 -0600 )edit