Ask Your Question

_djani_'s profile - activity

2017-07-24 06:39:25 -0600 received badge  Self-Learner (source)
2017-07-23 21:59:32 -0600 commented question How to initialize neural network?

Thank You sir. I have chaged to type CV32FC1 and rearrange matrix (I forgot that in Matlab I use transpose), so now I have this code and it works. Once again thanks for Your help.

Mat_<int> layers(4,1,CV_16U);
layers(0) = 2;     // input
layers(1) = 100;  // hidden
layers(2) = 100;  // hidden
layers(3) = 1;      // output
ann_og->setLayerSizes(layers);
Mat trainData_tr;
transpose(trainData,trainData_tr);
ann_og->setActivationFunction(ml::ANN_MLP::SIGMOID_SYM,0,0);
ann_og->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 300, 0.0001));
ann_og->setTrainMethod(ml::ANN_MLP::BACKPROP, 0.0001);
ann_og->train(trainData_tr, ml::COL_SAMPLE, trainClass);
2017-07-23 14:48:23 -0600 asked a question How to initialize neural network?

Hello everyone. I have question; how to initalize Neural Network? I implemented Neural Network in MATLAB, and now I want to do same in OpenCV. Basically, I have training data as Mat (size 110 x 2), and my train classes have size (110 x 1). Here is code I am trying to compile, but it throws exception ( something about number of rows and columns).

Mat_<int> layers(4,1,CV_16U);
layers(0) = 2;     // input
layers(1) = 100;  // hidden
layers(2) = 100;  // hidden
layers(3) = 1;      // output, 1 pin per class.
ann->setLayerSizes(layers);
ann->setActivationFunction(ml::ANN_MLP::SIGMOID_SYM,0,0);
ann->setTermCriteria(TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 300, 0.0001));
ann->setTrainMethod(ml::ANN_MLP::BACKPROP, 0.0001);
ann>train(trainData, ml::ROW_SAMPLE, trainClass);

I also tried other options for number of layers (I use 110 for layers(0), etc.) but it failed.