此代码是关于使用 com.googlecode.javacv.cpp 训练神经网络的,当我制作 .create 方法时出现错误
static void train (CvMat TrainData, CvMat classes, int nlayers,int numOfClasses)
{
CvANN_MLP C=new CvANN_MLP();
CvMat layerSizes = cvCreateMat(1, 3, CV_32FC1);
layerSizes.put(0, 0, TrainData.cols());//put or rows or ???
layerSizes.put(0, 1, nlayers);
layerSizes.put(0, 2, numOfClasses);
double alpha=1.0;
double beta=1.0;
C.create(layerSizes, CvANN_MLP.SIGMOID_SYM, alpha,beta );//there is an error here
//OpenCV Error: Bad argument (The array of layer neuron counters must be an integer vector) in //CvANN_MLP::create, file ......\src\opencv\modules\ml\src\ann_mlp.cpp,第 230 行
//Prepare trainClasses
//Create a mat with n trained data by m classes
CvMat trainClasses = null;
trainClasses.create(TrainData.rows(), numOfClasses, opencv_core.CV_32FC1);
for( int i = 0; i < trainClasses.rows(); i++ )
{
for( int k = 0; k < trainClasses.cols(); k++ )
{
int [] ClassesNumber =new int[1];
//If class of data i is same than a k class
classes.get(i, k );
if(k == ClassesNumber[0])
{
trainClasses.put(i, k);
}
else{
trainClasses.put(i, k);
}
}
}
CvMat weights = cvCreateMat( 1, TrainData.rows(), opencv_core.CV_32FC1 );
cvSet(weights, CvScalar.ONE);
//Scler 1111111111
//Learn classifier
C.train(TrainData, trainClasses, weights,null,new CvANN_MLP_TrainParams(), 0);
// 训练=真;
}