opencv train cascade in less than 2 hours - opencv

I'm new to opencv I want to detect a fire object and I'm training a fire classifier using opencv traincascade, as I read various tutorials everyone said that training will use up days or even weeks.
I have 700 positives and 3k negatives, I read that I should not use all positive to train and ratio of 1:2 in positive negative so this is what I inputted
opencv_traincascade -data classifier -positive.vec -bg negatives.txt -numPos 500 -numNeg 1000 -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -precalcValBufSize 1024\ -precalcIdxBufSize 1024 -mode ALL PAUSE
the training only took 2 hours, Do I need to worry about it? is there something wrong with my samples?

Related

OpenCV Haar Classifier: training stops prematurely

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?

Open CV Haar cascade training can't be trained

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.

Haar- Cascade object detection OpenCV - .xml file classifier not detecting properly

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.

opencv cascade haartraining bad result

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!

haar classifier: XML file got from haar cascade

I used typical haar-cascade of OpenCV.
And setup stages as 5 in training process,but in xml & cascade folder only 3 stages were found.
Why I got fewer stages than expected?
Any solutions?
Take this example training command:
opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\
-numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\
-numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024\
-precalcIdxBufSize 1024
This has a maxFalseAlarmRate of 0.5, when the classifier reaches this value it will finish.
For your problem, I imagine you have set the numStages to 5 but after 3 stages it has reached the maxFalseAlarmRate and completed the training.
In order to confirm/dispell this you would need to provide:
Your training command (as above)
The output from your last training stage.
You most likely have not provided traincascade enough information to learn from. This is most likely because we humans are incredibly lazy and hate to work. It would have kept going if it thought it could learn more from the data you specified.
Take more positives. Remember that you can take multiple images of your object a slightly tilted angles (10º-20º or so). And be sure to provide at least hundreds of your objects, especially if there is quite a bit of variation between your objects, like there are with faces.
If you're still stuck, see this tutorial I wrote that can hopefully help you and others: http://johnallen.github.io/opencv-object-detection-tutorial/

Resources