1 | initial version |
your ANN needs "one-hot-encoded" responses to train, [1,0] for label 0, and [0,1] for label 1.
you can either change the csv file, so it has 16 data numbers and 2 response labels at the end:
0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1
1,1,1,1,1,0,0,1,1,0,0,1,,1,1,1,1,1,0
and use
Ptr<TrainData> datos = TrainData::loadFromCSV("/home/josejacomeb/QT/MLP_DosCapas/mlp_2capas.csv", 0, 16, 18);
(btw, not ROW_SAMPLE there !)
or, fix the responses after reading your unchanged csv:
Mat responses(num_samples, 2, CV_32F, 0.0f);
for (size_t i=0; i<num_samples; i++) {
int id = (int)labels.at<float>(i); // 0 or 1
responses.at<float>(id) = 1;
}
2 | No.2 Revision |
your ANN needs "one-hot-encoded" responses to train, [1,0] for label 0, and [0,1] for label 1.
you can either change the csv file, so it has 16 data numbers and 2 response labels at the end:
0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1
1,1,1,1,1,0,0,1,1,0,0,1,,1,1,1,1,1,0
and use
Ptr<TrainData> datos = TrainData::loadFromCSV("/home/josejacomeb/QT/MLP_DosCapas/mlp_2capas.csv", 0, 16, 18);
(btw, not ROW_SAMPLE there !)
or, fix the responses after reading your unchanged csv:
Mat responses(num_samples, 2, CV_32F, 0.0f);
for (size_t i=0; i<num_samples; i++) {
int id = (int)labels.at<float>(i); // 0 or 1
responses.at<float>(id) = 1;
}
ann->train(datos->getTrainSamples(), 0, responses);
3 | No.3 Revision |
your ANN needs "one-hot-encoded" responses to train, [1,0] for label 0, and [0,1] for label 1.
you can either change the csv file, so it has 16 data numbers and 2 response labels at the end:
0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1
1,1,1,1,1,0,0,1,1,0,0,1,,1,1,1,1,1,0
and use
Ptr<TrainData> datos = TrainData::loadFromCSV("/home/josejacomeb/QT/MLP_DosCapas/mlp_2capas.csv", 0, 16, 18);
(btw, not ROW_SAMPLE there !)
or, fix the responses after reading your unchanged csv:
Mat labels = datos->getTrainResponses();
Mat responses(num_samples, 2, CV_32F, 0.0f);
for (size_t i=0; i<num_samples; i++) {
int id = (int)labels.at<float>(i); // 0 or 1
responses.at<float>(id) responses.at<float>(i, id) = 1;
}
ann->train(datos->getTrainSamples(), 0, responses);