MLP Train iteration limit - bug?

asked 2016-06-01 06:42:13 -0500

majkel gravatar image

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 ;)

edit retag flag offensive close merge delete

Comments

you need more images. 1 or 2 per class are definitely not enough. (try 100 per class)

berak gravatar imageberak ( 2016-06-01 06:50:55 -0500 )edit

but when i train the NN with 5 images it can't recognise this 5 images again! i'm not talking about generalization feature and learning, the problem is with learning iteration - I decreased the hidden layer size to 50 and it can learn and recognize all 4 images per class ;)

majkel gravatar imagemajkel ( 2016-06-01 09:30:46 -0500 )edit

btw, the aim of machine-learning is to generalize the objects in question from the input, so you should never test with your train input

berak gravatar imageberak ( 2016-06-01 13:03:17 -0500 )edit

if the NN can't recognize the traning images it also can't recognise testing images ;)

majkel gravatar imagemajkel ( 2016-06-01 13:18:36 -0500 )edit

that's not true. if you use your train images(only) for testing, you're optimizing for the wrong case.

berak gravatar imageberak ( 2016-06-01 13:26:06 -0500 )edit

I'm not optymising yet, just checking the learning process - if I get complete garbage and nonsense result from learning data the NN is useless. And the question was only about learning bug - i just wan't to increase traning iterations to increase hidden layer size...

majkel gravatar imagemajkel ( 2016-06-02 09:58:44 -0500 )edit