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:
Your assistance will be duly appreciated.
Regards.