Ask Your Question
0

How to train data for Neural Network?

asked 2016-04-05 16:41:03 -0600

bob409 gravatar image

updated 2016-04-06 01:46:32 -0600

berak gravatar image

How to input labels for classes in NN. Are they like SVM give different labels to each class. I have not really understood how to create the training class for neural network? I do not know how to use it for training I have tried the following way:

void mlp(cv::Mat& trainingData, vector<int>& index)
{
    int input_neurons = 8;
    int hidden_neurons = 100;
    int output_neurons = 12;
    Mat layerSizes = Mat(3, 1, CV_32SC1);
    layerSizes.row(0) = Scalar(input_neurons);
    layerSizes.row(1) = Scalar(hidden_neurons);
    layerSizes.row(2) = Scalar(output_neurons);

    Ptr<ml::ANN_MLP> mlp = ml::ANN_MLP::create();
    mlp->setLayerSizes(layerSizes);
    mlp->setTrainMethod(ml::ANN_MLP::SIGMOID_SYM);
    mlp->setTermCriteria(TermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 1000, 0.00001f));
    mlp->setTrainMethod(ml::ANN_MLP::BACKPROP,0.1f,0.1f);
    mlp->setActivationFunction(ml::ANN_MLP::SIGMOID_SYM, 1, 1);

    Mat trainClasses;

    cout << "Poker" << endl;
    trainClasses.create(trainingData.rows, 12, CV_32FC1);
    for (int i = 0; i < trainClasses.rows; i++)
    {
        trainClasses.at<float>(i, index[i]) = 1.f;
    }

    cout << "Row of trainClass: " << trainClasses.cols << endl;
    cout << "Row of trainData: " << trainingData.cols << endl;
    cout << "Koker" << endl;
    Ptr<ml::TrainData> td = ml::TrainData::create(trainingData, ml::ROW_SAMPLE, trainClasses);
    mlp->train(td);
    cout << "Training Done" << endl;

    mlp->save("neural_network.xml");

}

When I am predicting, I am getting the following response:

[-4.4227011e+0008,-404295997e+008,-4.4214237e+008,-4.3398125e+008,.......]

What is wrong and how to interpret the response from an ANN?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-04-06 02:29:13 -0600

berak gravatar image

trainClasses.create(trainingData.rows, 12, CV_32FC1); does not initialize data, i guess, you wanted something like: trainClasses = Mat::zeros(trainingData.rows, 12, CV_32FC1);

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-05 16:41:03 -0600

Seen: 919 times

Last updated: Apr 06 '16