Opencv haartraining - Out of memory

Asked

Viewed 295 times

9

I have 30 positive images and 60 negative images. When I tried to run haartraining with 4GB of memory and Quadcore processor, I get this error message:

OpenCV ERROR: Insufficient memory (Out of memory)
  in function cvAlloc, cxalloc.cpp(111)
Terminating the application...
  called from cvUnregisterType, cxpersistence.cpp(4933)

The command I executed was:

./opencv-haartraining -vec vector/myvector.vec -bg negatives.txt -npos 24 -nneg 55 -mem 2048 -mode ALL -w 86 -h 150

The computer at the time of the tests was using less than 800 MB of memory, but during the execution of the above command, the memory used changes to more than 3GB and more than 1 GB of swap, all in less than 5 minutes of program execution.

Any suggestions of what can be done to solve this problem?

  • You can have a memory Leak in your code. Or does your code need to allocate all this memory even? It has how to show more of the code?

  • How big is your myvector.vec? I’ve run haartraining on a 4GB RAM computer for more than 3k images using these parameters: "opencv-haartraining -data Haarcascade -vec samples.vec -bg negatives.dat -nstages 18 -minhitrate 0.999 -maxfalsealarm 0.5 -npos 2032 -nneg 3000 -w 64 -h 128 -nonsym -mem 768 -mode ALL"

  • @Lucasnunes, the library I am using to generate the classifiers is available at: https://github.com/mrnugget/opencv-haar-classifier-training. You may have some memory within it even if you have some memory Leak.

  • @vs06, the file . vec is empty.

  • The file . vec is the file that contains all positive symmetric images. You came to generate it from the application "opencv-createsamples"?

  • Thanks @vs06, several reasons generated over-memory allocation, the first of which I didn’t notice the createsamples errors, and the second reason is that the size and quantity of the positive and negative images were being allocated in memory. Now it’s processing normally.

Show 1 more comment

2 answers

5


According to the comments on the question, I was passing many relatively large images (-w 86 -h 150) as a parameter. As the Opencv engine allocates the images and examples in memory before writing to disk, overflow occurred due to size and quantity.

To solve the problem, I reduced the size of the sample images no longer burst my machine’s memory.

  • 1

    Hello Elexsandro. Glad your problem has been solved. But can you improve this answer a little bit so that it also serves to help other people in the future? The problem is quite clear (excess memory usage), but the solution is not at all clear. If you elaborate better the answer wins my positive votes on it and the question. :)

  • 1

    @Luizvieira, thanks for the feedback, improved the response as requested :)

  • Thanks! As promised, I voted in your posts. :)

0

When the haarcascade is used we must specify the same parameters used in createsamples, as -w and -h.

  • 1

    Oi Fabricio. The commentary What I did to the author of the question is also valid here for you. It would be important to improve your answer, because the way it is I think it is of little help to another user (especially if he is less experienced with the use of the library in question).

  • 1

    Okay. Thanks for the tip. The next ones will be better. ;)

  • Hello you are running via DOS or installed python on Windows ? I am doing the same procedure. In my case no error at all but processing for and error and I can’t decrease further the positive Magnes than they already are understand I have 154 positive 100 x 55 and 600 negative

Browser other questions tagged

You are not signed in. Login or sign up in order to post.