Set number of output nodes of Artificial Neural Network to a value other than 1
I am working on a project where I need to classify images using Artificial Neural Network (ANN). I have successfully trained ANN with 1 output node as shown in code below. How can I set number of output nodes to another value other than 1 (e.g. 50). Kind regards
trainANN(Mat hists, vector<int> labels)
{
int cols = hists.cols;//size of input layer must be equal to this number of cols
int rows = hists.rows;
Mat responses(labels);//create a matrix of responses from vector labels
responses.convertTo(responses, CV_32FC1);//convert responses (labels) from int to float
Ptr<TrainData> trainData = TrainData::create(hists, ROW_SAMPLE, responses);//create training data
Ptr<ANN_MLP> ann = ml::ANN_MLP::create();
vector<int> layers = { cols,1000,500,1 };//layers
ann->setLayerSizes(layers);//set the layer sizes(SIZES)
ann->setActivationFunction(ml::ANN_MLP::SIGMOID_SYM);
cout << "Training ANN..." << endl;
ann->train(trainData);
bool trained = ann->isTrained();
if (trained)
{
cout << "Artificial Neural Network Trained"<<endl;
ann->save(".\\Trained Models\\ANN.xml");
}
}
think of how the sigmoid activation works, and you'll see, that only 0 and 1 are valid values for a label, and that you also will need N output nodes for N classes
Thank you Berak. I have 60 classes and 10 images per class. I have a one dimensional matrix of labels with values between 1 and 60. I have a clue: which is to make this labels matrix a 600 by 60 Mat with my labels as 1 or 0 in columns. I would like to request how help on how to make this binary matrix of labels
^yes, exactly. it's called "one-hot encoding".