0
我試圖用OpenCV 3.1.0實現神經網絡。當預測我得到一個具有-1。#QNAN值的向量時。我究竟做錯了什麼?使用opencv 3.1.0的神經網絡
// train
Ptr<ANN_MLP> ann = ml::ANN_MLP::create();
Mat layers(1, 3, CV_32F);
layers.at<float>(0) = features.cols;
layers.at<float>(1) = nlayers;
layers.at<float>(2) = numLabels;
ann->setActivationFunction(ANN_MLP::SIGMOID_SYM);
ann->setLayerSizes(layers);
Mat trainClasses;
trainClasses.create(features.rows, numLabels, CV_32F);
for (int i = 0; i < trainClasses.rows; i++)
{
for (int k = 0; k < trainClasses.cols; k++)
{
if (k == labels[i])
trainClasses.at<float>(i, k) = 1;
else
trainClasses.at<float>(i, k) = 0;
}
}
Mat weights(1, features.rows, CV_32F, Scalar::all(1));
Ptr<TrainData> tdata = TrainData::create(features, ROW_SAMPLE,
trainClasses, Mat(), Mat(), weights, Mat());
ann->train(tdata);
// predict
Mat output(1, numLabels, CV_32F);
ann->predict(test_data, output);
我有同樣的問題,試試這個http://stackoverflow.com/a/36885722/6256956 – Theese