Using The FLANN Benchmarking Programs

FLANN has a very nice and generic interface to work with various indexing algorithms. One only needs to specify the index method and parameters when building the index, and the same API can be used to load the index and conduct online search.

Here's how to use the "flann_index" and "flann_search" programs provided in the KGraph SDK.

The following command will build a KDtree and save that to the file sift.kdtree.

$ flann_index sift.data sift.kdtree -A kdtree -P trees%=4

And the following for kmeans index.

$ flann_index sift.data sift.kmeans -A kmeans -P branching%=4 -P cb_index!=0.2

All Supported Indices

The index algorithm is specified with "-A", and parameters to the algorithm is passed with multiple "-P" in the form of "-P name%=integer" or "-P name!=float". (It is unfortunate that I haven't figured out a way to uniformly deal with integer parameters and float ones, so a little bit Basic-like modifiers need to be used.)

For search, one only need to provide the index file no matter how it was built.

$ flann_search sift.data sift.index sift.query  [sift.output] [--eval goldstandard]

"sift.index" is "sift.kdtree" or "sift.kmeans" or other indices previously built. Goldstandard is generated by searching with brutal force (a index created with "-A linear".)

All FLANN Indices Supported

$ ./flann_index --help
flann_index [-A algo] [-P key=value ...] <data> [output]
General options:
  -h [ --help ]                    produce help message.
  --data arg                       input path
  --output arg                     output path
  -A [ --algorithm ] arg (=linear) linear, kdtree, kmeans, hier, comp, auto,
                                   lsh
  -P arg                           parameters passed to flann
  -v [ --verbose ]

Algorithm specific parameters are passed as '-P name%=value' (integer) or '-P name!=value' (float).
Available parameters and their default values:
linear
kdtree
           trees=4
kmeans
           branching=32
           iterations=11
           center_init=0 (RANDOM 0, GONZALES 1, KEMANSPP 2)
           cb_index=0.2
hier[archical]
           branching=32
           center_init=0 (RANDOM 0, GONZALES 1, KEMANSPP 2)
           trees=4
           leaf_max_size=100
comp[osite]
           trees=4
           branching=32
           iterations=11
           center_init=0 (RANDOM 0, GONZALES 1, KEMANSPP 2)
           cb_index=0.2
auto[tuned]
           target_precision=0.8
           build_weight=0.01
           memory_weight=0
           sample_fraction=0.1
lsh
           table_number=12
           key_size=20
           multi_probe_level=2