Ask Your Question

Insufficient memory in function cvAlloc, how to release memory?

asked 2018-03-02 11:31:37 -0500

Joshitha gravatar image

updated 2018-03-04 11:39:07 -0500

I have tried training my own classifier for a couple of times now (to detect cows) and just when I finally fine-tune my images in the positives data-set, I run into this while training: Error

I realize I have to release memory in order to free some space and referred to THIS

But I am actually a little confused as to how to proceed further. Can anyone help with an optimal solution for this so that I can resume my training? Thanks in advance.


  1. my positives vary from 20-25KB on an average and negatives from 30-55KB.
  2. Positives: 355x 280 pixels, I read somewhere that w,h must maintain this aspect ratio , hence used -w 71 -h 56
  3. Im using 133 positives and 200 negatives, cows in positives all face the left side ( same profile)


text version:

PS E:\FYP\haar training\jo_haartrain> .\haartraining.exe -data cascades -vec vector/vector.vec -bg negative/bg.txt -n pos 67 -nneg 200 -nstages 12 -mem 2000 -mode ALL -w 64 -h 32

Data dir

name: cascades

Vec file name: vector/vector.vec

BG file name: negative/bg.txt

Num pos: 67

Num neg: 200

Num stages: 12

Num splits: 1 (stump as weak classifier)

Mem: 2000 MB

Symmetric: TRUE

Min hit rate: 0.995000

Max false alarm rate: 0.500000

Weight trimming: 0.950000

Equal weights: FALSE

Mode: ALL

Width: 64

Height: 32

Max num of precalculated features: 1309083

Applied boosting algorithm: GAB

Error (valid only for Discrete and Real AdaBoost): misclass

Max number of splits in tree cascade: 0

Min number of positive samples per cluster: 500

Required leaf false alarm rate: 0.000244141

Tree Classifier Stage

+---+ | 0| +---+

Number of features used : 1472939

Parent node: NULL

* 1 cluster *

edit retag flag offensive close merge delete


please be so kind, and replace the screenshot with a text version, thank you !

(also forget the aishack page, that's from opencv1.0, and no more relevant)

berak gravatar imageberak ( 2018-03-02 11:34:13 -0500 )edit

is that 32bit, somehow ?

berak gravatar imageberak ( 2018-03-02 12:10:37 -0500 )edit

How much RAM do you have? Also, answer berak's question about using the 32-bit memory space. If you use Win32/x86 as the architecture of your executable file, you are limited to 4GB of RAM (including the memory space taken up by Windows, which is a hog).

sjhalayka gravatar imagesjhalayka ( 2018-03-02 13:31:28 -0500 )edit

could it be this file ?

LBerger gravatar imageLBerger ( 2018-03-02 13:39:30 -0500 )edit

Yes, Win32/x86, 4GB RAM. I read somewhere that the images are stored during the processing, how do I release this to fee some memory?

Joshitha gravatar imageJoshitha ( 2018-03-02 22:36:26 -0500 )edit

opencv version : is it opencv 1.0 ?

LBerger gravatar imageLBerger ( 2018-03-03 02:13:05 -0500 )edit

@LBerger, not nessecarily. sad as it is, the harrrrr training code is still mostly c-based.

berak gravatar imageberak ( 2018-03-03 02:50:13 -0500 )edit

@LBerger , no, it is opencv 3.4.0. any idea how i can free up the opencv cache n proceed with my training?

Joshitha gravatar imageJoshitha ( 2018-03-03 05:00:22 -0500 )edit

@Joshitha , unfortunately you cannot free anything there.

"Win32/x86, 4GB RAM" -- there's your problem.

berak gravatar imageberak ( 2018-03-03 05:20:17 -0500 )edit

oh no..!!! this means i cant train anything anymore? even if i reduce the number of images, i get the error :(

Joshitha gravatar imageJoshitha ( 2018-03-03 06:04:35 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-03-04 11:41:41 -0500

Joshitha gravatar image

edit made @berak when i ran it for -mem 1024 , training continued. This was probably my human mistake, I read that you can increase the memory upto 2BG but 2000 would be ideal. Should have checked with my architecture compatibility first. Thank you all

edit flag offensive delete link more


Hi Joshitha, I am running exactly the same classifier and ran into the same problem several times. My width and heights are 100 * 100 as I am trying to detect buildings. I have tried to both increase and decrease the -mem but regardless of the value I assign, this error pops up when the memory gets near 2000MBs in task manager for the process. Can you help me please? thanks in advance

mahdinj gravatar imagemahdinj ( 2019-03-31 06:11:02 -0500 )edit

Question Tools

1 follower


Asked: 2018-03-02 11:31:37 -0500

Seen: 737 times

Last updated: Mar 04 '18