Ask Your Question
0

How to initialize neural network?

asked 2017-07-23 14:44:30 -0600

_djani_ gravatar image

updated 2017-07-23 14:51:52 -0600

LBerger gravatar image

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.

edit retag flag offensive close merge delete

Comments

Something ? may be it could help.

layers(3) = 1; means you have got only one class.

train classes must be a mat with CV32FC1 type

LBerger gravatar imageLBerger ( 2017-07-23 15:00:57 -0600 )edit

Adding the actual errors could help us ...

StevenPuttemans gravatar imageStevenPuttemans ( 2017-07-24 06:39:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-07-23 17:05:08 -0600

_djani_ gravatar image

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);
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-07-23 14:44:30 -0600

Seen: 296 times

Last updated: Jul 23 '17