Errors when predicting from a Neutral Network
Hello everyone,
I am trying to train a neutral network in opencv using one hidden layer network. Everything seems fine but the program crashes when the predict function for the model is called. Below is my code:
float sc[6] = { 0.3, 0.5, 1, 1, 0.2, 0.4 };
float sc1[3] = { 0.75, 0.81, 0.93 };
float sc2[2] = { 0.2, 1};
Mat traindata = Mat(3,2,CV_32FC1,&sc);
Mat trainlabel = Mat(3, 1,CV_32FC1,&sc1);
Mat testdata = Mat(1, 2,CV_32FC1,&sc2);
Ptr<ml::ANN_MLP> mlp = ml::ANN_MLP::create();
mlp->setActivationFunction(ml::ANN_MLP::SIGMOID_SYM);
mlp->setTrainMethod(ml::ANN_MLP::BACKPROP);
mlp->setBackpropMomentumScale(0.1);
mlp->setBackpropWeightScale(0.1);
mlp->setTermCriteria(TermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 1000, 1e-6));
Mat layers = Mat(3, 1, CV_32SC1);
layers.row(0) = Scalar(2);
layers.row(1) = Scalar(3);
layers.row(2) = Scalar(1);
//layers.row(3) = Scalar(5);
mlp->setLayerSizes(layers);
mlp->train(traindata,ml::ROW_SAMPLE,trainlabel);
Mat responses = Mat(3,1,CV_32FC1);
mlp->predict(testdata,responses);
float result = responses.at<float>(0, 0);
The error message is given below:
Unhandled exception at 0x00007FFE0076855C (opencv_world310d.dll) in fetchvideoapp.exe: 0xC0000005: Access violation reading location 0x000001D3A69DF000.
Your assistance will be duly appreciated.
Regards.
hi berak this only error message Unhandled exception at 0x00007FFE0076855C (opencv_world310d.dll) in fetchvideoapp.exe: 0xC0000005: Access violation reading location 0x000001D3A69DF000.
weirdly, i can't reprocuce the crash, it just returns [-1.INF] (or [-nan] on linux) .
but i think, your traindata/labels are
schrottnot nice, for a classification you would need one output node per class (and a 2d, numFeatures x numClasses response Mat for training)