Active Basis C++ Code
QuickStart|
Implementation |
Usage |
Consistency |
Screen Shot
Version problem:
The package compiles in CMake 2.4 and VC 9.0.
If you use CMake 2.6, some workaround is needed.
If you use an older version of VC, a full version
of boost is needed.
Follow the following steps to start playing
- Download the code at
active_basis_release_1,
unzip it to some folder (say active_basis_cpp_dir).
-
Download and install CMake.
-
Open CMake,
- specify 'active_basis_cpp_dir\build\' as binary directory,
- spceify 'active_basis_cpp_dir\' as source directory,
- then click 'Configure', then wait a minute and click 'Configure' again, then click 'OK'.
- This will generate VC project files in 'active_basis_cpp_dir\build' folder.
- Open 'active_basis_cpp_dir\build\ACTIVE_BASIS_Prj.sln', switch to release configuration and compile all projects.
- [Exp1]
Go to folder 'active_basis_cpp_dir\data\ex1_car' and
- run tilt.bat ---
This will generate 'nlf_*' files in 'model' folder,
which contain the natural image ensemble statistics.
- run ab.bat ---
This will generate 'learned_sketches_*' files in 'model'
folder, which contain learned sketches.
- run vis_active_basis.bat ---
This will read the visualization file generated by ab.bat in
folder 'tmp' and visulize them. Press enter on the visulization window
to continue.
- open param.ini and modify parameters to try again.
- [Exp3]
Go to folder 'active_basis_cpp_dir\data\ex3_horse' and
- run tilt.bat
- run ab.bat
- run vis_active_basis.bat to visulize, optional
- run abtest.bat --- This will test the learned model and draw ROC.
- open param.ini and modify parameters to try again.
- [Exp4]
Go to folder 'active_basis_cpp_dir\data\ex4_hs_hrs_butf' and
- run tilt.bat
- run abem.bat --- This will use EM algorithm to do clusting.
This will generate 'learned_EM_* files' in '..\..\data\model' folder,
which contain learned EM model.
- run vis_active_basis_em.bat to visulize, optional
- open param.ini and modify parameters to try again.
I use the following libraries, and pack them together in the compressed package,
so you need not to download them yourself.
- OpenCV --- reading image, filtering.
- Boost::ublas --- matrices and vectors.
- Boost::program_options
--- command line parsing and configuration file parsing.
- PlPlot --- visualization.
If you want to debug the project containing PlPlot, you need download and install it.
I use CMake to generate the project files.
CMake is a very small and neat tool.
I convert all double data to float, which results in nearly no
accuracy loss but reduces computation and storage.
Open the project, you will find 6 main projects:
- tilt.exe --- Corresponde to tilt.m+Chistog.c in Matlab code.
- active_basis.lib --- A library project packs all main algorithms for all the followed
projects.
- active_basis_learn.exe --- Corresponde to ABlearn.m+Clearn.c in Matlab code.
- active_basis_test.exe --- Corresponde to ABtest.m+ABtst_one.m+Ctesting.c in Matlab code.
- active_basis_em_learn.exe --- Corresponde to ABlearn.m+Clearn.c in EM version of Matlab code.
- active_basis_em_test.exe --- Testing the ROC of EM model, No corresponding Matlab code.
The project also contains 3 visulization projects:
- vis_active_basis.exe
- vis_active_basis_em.exe
- vis_active_basis_em_test.exe
Additionally, it also contains 3 support projects:
- dir_utils.lib --- Warper of Boost::program_options for command-line options.
- stat_utils.lib --- Histogram calculation, ROC computing etc.
- ublas_utils.lib --- Several input and output functions related to boost::ublas.
- prog_opt.lib --- Boost::program_options, I pack it into the project for self-containing.
How to debug in VC:
- Switch to Debug configuration and compile all.
- Select the interested project and set as StartUp project.
- View project property, go 'Debuging'.
- Set the command arguments, referring to the '.bat' file in the 'data' folder.
- Set the working directory as 'active_basis_cpp_dir\bin\debug'.
The command-line options. All executables accepts several of the following
options
- --train_pos_dir --- folder of training positive examples
- --train_neg_dir --- folder of training negative examples
- --test_pos_dir --- folder of testing positive examples
- --test_neg_dir --- folder of testing negative examples
- --temp_data_dir --- folder of temporary data (e.g. visualization)
- --param_file --- full path and name of the parameter file
- --model_dir --- folder of learned model
An example:
active_basis_em_test --test_pos_dir=%ddir%\posTest --test_neg_dir=%ddir%\negTest --param_file=%ddir%\param.ini --model_dir=%ddir%\model\
I test the code on 'Head-Shoulder' data and 'Header-Shoulder-Horse-Butterfly' mixtrain data.
- For single template version, if I import the filtering results from matlab,
the learned templates and final ROC will be exactly the same.
- For EM version, if I import the filtering results from matlab,
the learned templates may be have minor differences due to double
-float conversion, but C++ version has
higher coding gain. For each template, there may exist one sketch has 2 pixels deviation.
- For single template version, if I use OpenCV filtering,
the learned templates scores and final ROC will have minor differences.
- For EM testing, there is no Matlab code for comparison.
PlPlot is really a good tool for scientific
plotting, I recomend everyone to use it.
Tilt
Learn
Test
Learn EM
QuickStart|
Implementation |
Usage |
Consistency |
Screen Shot
Haifeng GONG