I have 616 positive image profile face and 3020 image negative and I use this code to make my vector sample:
createsamples.exe -info positive/info.txt -vec vector/facevector.vec -num 616 -w 24 -h 24
size of vector 694 KB
size of image 630 * 480
and I use this for haartraining:
haartraining.exe -data cascades -vec vector/facevector.vec -bg negative/bg.txt -npos 616 -nneg 3020 -nstages 19 -nsplits 2 -nonsym -minhitrate 0.999 -maxfalsealarm 0.5 -mem 1024 -mode ALL -w 24 -h 24 PAUSE
and when it finishes I change it to cascade by:
haarconv.exe data myfacedetector.xml 24 24
and I have only 56 cascade size also my training data size all (every stage) its 1 KB or 2KB. When I test it it dosen't detect any face also the training positive image is not detected.
First thing, in haartraining.exe command -npos is not the number of poisitive images you have; it is the number little less than the number of samples (say 0.9*(number of samples)).
Second thing, I don't see how many samples you are creating using createsamples.exe command. Again, you don't specify number of positive images here; you should specify how many samples you want to create using those positive images you have. Please study the parameters again.
Hope this helps!
Related
I have been trying to train image databases to detect faces using Haar cascades. I have made 2 attempts:
1) I have used the following database for positive images:
http://robotics.csie.ncku.edu.tw/Databases/FaceDetect_PoseEstimate.htm#Our_Database_ (6660 images)
For negative images I have used this database:
https://github.com/sonots/tutorial-haartraining/tree/master/data/negatives (3300 images)
I have used this command to train the samples:
opencv_createsamples -info info.dat -vec samples2.vec -w 32 -h 24 -num 6660
I have used this command to train the data:
opencv_traincascade -data ./classifier3 -vec samples2.vec -bg bg.txt -numPos 6000 -numNeg 12000 -numStages 30 -precalcValBufSize 5120 -precalcIdxBufSize 5120 -numThreads 12 -acceptanceRatioBreakValue 10e-5 -w 32 -h 24 -minHitRate 0.99 -maxFalseAlarmRate 0.5 -mode ALL
The training goes on up to stage 9. Then the acceptanceRatio break value is crossed.(The required acceptanceRatio for the model has been reached to avoid over-fitting of training data. Branch training terminated.)
I don't understand the issue here. I have only used the recommended values for the parameters. I had tried changing the minHitRate to 0.95, yet the result is the same. I can think of some potential reasons:
i) I had used the positive images directly without cropping. But I don't
think that should be an issue, as the background is completely plain.
ii) The image database contains faces in different poses. That could lead
to complications while training. Is it a good idea to train faces
under different poses using the same cascade classifier? Or should I
use different classifiers for each pose?
iii) My negative images might be too different compared to the positive
images. Is that the case? If yes, what kind of negative images should
I be looking for?
I tried testing the cascade.xml file on a few sample images, but nothing is detected at all.
2) Keeping in mind the potential reason i), I used this database already cropped, for positive images: http://conradsanderson.id.au/lfwcrop/ (around 13000 images)
But still the problem persists. This time it trains upto stage 11. In this case I used -numPos as 8000 -numNeg as 20000( increased the ratio to give the training more negative samples), -w as 24 and -h as 24.
Can anyone please guide me here?
hello I'm trying to develop a haar cascade classifiers, I was able to run the basic example with detection of cars, so I tried to identify a fruit, I download some images of pears and then generate the positive file and then the vector file, until this point everything is ok, I tested the vector file with the command:
opencv_createsamples -vec vector.vec
so I tried to generate the xml cascade classifier wtih the next command and options:
opencv_traincascade -data images/cascade -vec vector.vec -bg bg.info -precalcValBufSize 2048 -precalcIdxBufSize 2048 -numPos 24 -numNeg 450 -numStages 10 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -w 24 -h 24
I get the next error:
PARAMETERS:
cascadeDirName: images/cascade
vecFileName: vector.vec
bgFileName: bg.info
numPos: 24
numNeg: 450
numStages: 10
precalcValBufSize[Mb] : 2048
precalcIdxBufSize[Mb] : 2048
stageType: BOOST
featureType: HAAR
sampleWidth: 24
sampleHeight: 24
boostType: GAB
minHitRate: 0.999
maxFalseAlarmRate: 0.5
weightTrimRate: 0.95
maxDepth: 1
maxWeakCount: 100
mode: BASIC
===== TRAINING 0-stage =====
<BEGIN
POS count : consumed 24 : 24
Train dataset for temp stage can not be filled. Branch training terminated.
Cascade classifier can't be trained. Check the used training parameters.
I wasn't able to find the error... is there an opencv guru that can help me?
This is old but I just solved it:
You should give for -numPos and -numNeg a number slightly lower than your total positive and negative samples, around 80% of that.
E.g. if you have 24 positive images, give -numPos 18.
Also, 24 positive samples is way too low. Try to increase it to at least 200.
I have been fiddling around with OpenCV's cascade trainer in an attempt to train my own classifier. The problem is that it has been training for 25+hours now and it is yet to even pass stage 1.
Initially, I ran it with the following command
nohup opencv_traincascade -data data -vec board.vec -bg bg.txt -numPos 580 -numNeg 1160 -numStages 2 -w 115 -h 153 -featureType LBP &
After about 24 hours, it wasn't able to get through even stage 1. A look into the nohup.out file, I realized that the default precalcValBufSize was set to 1024Mb. I figured maybe increasing this to 4096Mb will help with the processing so I went ahead and re-started the training with the following command
nohup opencv_traincascade -data data -vec board.vec -bg bg.txt -numPos 580 -numNeg 1160 -numStages 2 -w 115 -h 153 -featureType LBP -precalcIdxBufSize 4096 -precalcValBufSize 4096 &
The training has been running for almost 25 hours now and it also hasn't even produced the XML file for stage 0.
A look into the process itself states that its using 8284M of virtual memory but 930M of physical memory and this shows all the files currently in use by the process. Its doing a great job burning through my cores but none at producing any results or even letting me know how far its got.
My question(s) is/are, is there any way of making it use more of my actual physical memory in attempt to speed it up? If not, are there any adjustments I need to make on my training dataset?
Side Note: I know the general standard for dataset size is 24x24 but I already tried that out and it was really horrible even after 10 stages.
At that size, my object's outline no longer attains its features correctly. At 24x24 or even 48x48 it looks like a giant horizontally distorted blob of black pixels without even some of its unique features being visible.
I bet that the problem is in samples size.
The bigger size requires muuuuch bigger memory buffers and much more time. Detecting features is quite a difficult operation.
You have to minimize your samples (don't forget to rerum cv_createsamples(...)). Samples shouldn't be square it may be 25*15 (make sure proportions are saved and the biggest side is about 30px).
You are using featureType LBP which itself is faster than Haar.
I have used the same parameters used in this tutorial.
perl bin/createsamples.pl positives.txt negatives.txt samples 1500\
"opencv_createsamples -bgcolor 0 -bgthresh 0 -maxxangle 1.1\
-maxyangle 1.1 maxzangle 0.5 -maxidev 40 -w 80 -h 40"
BUT changed the numPos parameter as it gave me an error of insufficient positive images.
ALSO had decreased the stages as it was below the desired accuracy rate(should be less than 0.0004) and mine was 0.0002.
Used these parameters.
opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 16 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 880 -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024
Got my cascade.xml file, but still not detecting properly. cascade.xml file took 3 days for processing.(Image attached)
Have used Opencv3.1.0
Please help!!!
IMAGE detected by classifier(Click to see)
What is the reason for using the parameter -bgthresh 0. From what I know the standard setting is 80, there is no reason to change parameters if you don't know what they do. Read up on that.
BUT changed the numPos parameter as it gave me an error of
insufficient positive images.
Have you checked that you really have 1500 positives, verify this together with the lines in your positives.txt file.
-numPos 880 -numNeg 600
Different opinions here, I recommend amount of neg = positives*2.
but still not detecting properly
What do you mean? What do you define as "properly"? From the example you provide I can see a proper detection with a possible false positive (the rectangle in the middle). Increase minNeighbors (in your code) – Parameter specifying how many neighbors each candidate rectangle should have to retain it.
I am building a Haar classifier. I have a set of 109 positive samples and 3000 negative samples. To increase my number of positive samples (to say 600), I try using the following command:
opencv_createsamples -vec out.vec -w 24 -h 24 -bg bg.txt -num 600 -info positives.dat
But I get the following error message:
positives.dat(109) : parse errorDone. Created 108 samples
How can I "force" opencv to produce the 600 samples from those 109 I have?
Opencv's default function for creating samples can only create as many as you have in your info file. A
lso, you should know if you use -info as opposed to -img it only resizes them to what you specified as h and w and grayscales all the images. It doesn't actually apply any transforms on them or superimpose them on background images. I'm not entirely sure what the point of the function is really...