# Revision history [back]

### MLP Train iteration limit - bug?

I am trying to learn my neural network to classify images. The whole learning data preparing and other stuffs work ok, the NN can learn recognizing 5 images (1 per class).

But when I get it 2 images per class, I got quite bad results - I think it's because the NN is undertained. So I updated the term criteria from 1000 to 10 000:

mlp->setTermCriteria(TermCriteria(
TermCriteria::Type::MAX_ITER,
10000,
0.0001
));


but with no success - still the same training time and recognizing results. It looks like the max iteration parameter only scale from 1-3000 - higher values don't make a difference.

So I tryied to update the weight in loop:

mlp->train(trainingData);

for (int i = 0; i < 100; i++) {
cout << "Traning iteration: " << i << endl;
mlp->train(trainingData
, ANN_MLP::TrainFlags::UPDATE_WEIGHTS
);
}


But only first 2-3 iterations take time, the other aren't learining anything and I just got text spaming in console.

My layers size are 1250-300-5. When I set the hidden layers to 100 i got better results and with 50 the results are perfect, so it means that the NN is working ok but I can't force the OpenCV to extend the learning time.

So my question is how to force the OpenCV ANN_MLP to pefrorm larger training? Any tips will be helpful ;)