1. Haier Training
Now, we use haartraining.exe to train our classifier. The training statement is as follows:
Usage:./haartraining -Data <dir_name> -VEC <vec_file_name> -BG <background_file_name> [-NPOs <number_of_positive_samples = 2000>] [-Nneg <number_of_negative_samples = 2000>] [-Nstages <number_of_stages = 14>] [-Nsplits <number_of_splits = 1>] [-MEM <memory_in_mb = 200>] [-Sym (default)] [-nonsym] [-Minhitrate <min_hit_rate = 0.995000>] [-Maxfalsealarm <max_false_alarm_rate = 0.500000>] [-Weighttrimming <weight_trimming = 0.950000>] [-Eqw] [-Mode <Basic (default) | core | all>] [-W <sample_width = 24>] [-H <sample_height = 24>] [-BT <dab | Rab | LB | gab (default)>] [-Err <misclass (default) | Gini | entropy>] [-Maxtreesplits <max_number_of_splits_in_tree_cascade = 0>] [-Minpos <min_number_of_positive_samples_per_cluster = 500>] |
Kuranov et. al. pointed out that 20*20 samples have the highest accuracy rate. In addition, the four split nodes have the best performance in the 18*18 dimension. For 20*20 samples, the two nodes are obviously better. The number of split nodes is the difference between the weak tree classifier of 2, 3, or 4 is smaller than their intermediate nodes.
In addition, there is a saying about level 20 training. Assuming that my test set represents a learning task, I can expect an error rate of 0.5 ^ 20 ≈ 9.6e-07 and a recognition rate of 0.999 ^ 20 ≈ 0.98.
Therefore, the sample size of 20*20 is used, and nsplit = 2, nstages = 20, minhitrate = 0.9999 (default: 0.995), maxfalsealarm = 0.5 (default: 0.5 ), weighttrimming = 0.95 (default: 0.95) is a better combination.
$ Haartraining-data haarcascade-VEC samples. vec-BG negatives. dat-nstages 20-nsplits 2-minhitrate 0.999-maxfalsealarm 0.5-NPOs 7000-nneg 3019-W 20-H 20-nonsym-MEM 512-mode all |
The "-nonsym" option is used for object classes without vertical (left-right) symmetry. If the object class is vertical symmetric, such as the positive face, use "-Sym (default )". This will increase the computing speed because only half of Haier-like features are put into use.
"-Mode all" uses an extension set similar to Haier features. By default, only vertical features are used. In addition to vertical features, all features can also use a feature set with a corner of 45 °.
"-MEM 512" is the pre-calculated memory size in MB. The default value is 200 MB.
In addition, some options are not used:
[-BT <dab | Rab | LB | gab (default)>] [-Err <misclass (default) | Gini | entropy>] [-Maxtreesplits <max_number_of_splits_in_tree_cascade = 0>] [-Minpos <min_number_of_positive_samples_per_cluster = 500>] |
# You can use OpenMP (Multi-processing ).
# One training lasts for three days.
2. generate an XML file
When Haier's training process ends completely, it will generate an XML file.
If you want to convert an intermediate Haier training output directory tree into an XML file, there is a directory in opencv/samples/C/convert_cascade.cProgramAvailable.
The input format is:
$ Convert_cascade -- size = "<sample_width> x <sampe_height>" |
Example:
$ Convert_cascade -- size = "20x20" haarcascade. xml |