1 | initial version |
hmm, tried your code, works fine here.
Mat_<float> trainData(13,6); trainData <<
35546, 0.62142855, 1125, 5, 145, 50,
40080, 0.60714287, 1202, 4, 151, 5,
38718, 0.60000002, 1136, 4, 150, 7,
39375, 0.60714287, 1182, 4, 148, 42,
39408, 0.61428571, 1217, 4, 151, 9,
38437, 0.60144925, 1129, 4, 148, 8,
39152, 0.62857145, 1433, 8, 124, 0,
39090, 0.58571428, 1191, 4, 150, 10,
37558, 0.60431653, 1090, 4, 149, 8,
38442, 0.55319148, 1125, 4, 150, 2,
42014, 0.61428571, 1249, 5, 145, 72,
37994, 0.55714285, 1037, 4, 149, 1,
38091, 0.62142855, 1396, 4, 149, 24;
Mat_<float> trainClass(13,2); trainClass <<
1, 0,
1, 0,
1, 0,
1, 0,
1, 0,
1, 0,
1, 0,
0, 1,
0, 1,
0, 1,
0, 1,
0, 1,
0, 1;
cv::Ptr<cv::ml::ANN_MLP> m_cvNeuronalNetwork = cv::ml::ANN_MLP::create();
cv::Mat cvLayer(3, 1, CV_32S);
cvLayer.at<int>(0,0) = 6;
cvLayer.at<int>(1,0) = 14;
cvLayer.at<int>(2,0) = 2;
m_cvNeuronalNetwork->setLayerSizes(cvLayer);
m_cvNeuronalNetwork->setActivationFunction(cv::ml::ANN_MLP::SIGMOID_SYM, 0.3,0.3);
m_cvNeuronalNetwork->setTrainMethod(cv::ml::ANN_MLP::BACKPROP,0.01,0.01);
m_cvNeuronalNetwork->setTermCriteria(cv::TermCriteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 1000, 0.000001));
m_cvNeuronalNetwork->train(cv::ml::TrainData::create(trainData, cv::ml::SampleTypes::ROW_SAMPLE, trainClass));
Mat_<float> cvTest(1,6); cvTest << 37994, 0.55714285, 1037, 4, 149, 1;
float fResult = m_cvNeuronalNetwork->predict(cvTest1);
cerr << fResult << endl;