una-dinosauria / local-search-quantization

State-of-the-art method for large-scale ANN search as of Oct 2016. Presented at ECCV 16.
MIT License
74 stars 11 forks source link
computer-vision cuda eccv-16 gpu julia multi-codebook quantization

Local-search Quantization

This is the code for the papers

The code in this repository was mostly written by Julieta Martinez and Joris Clement.

Dependencies

Our code is mostly written in Julia, and should run under version 0.6 or later. To get Julia, go to the Julia downloads page and install the latest stable release.

We use a number of dependencies that you have to install using Pkg.install( "package_name" ), where package_name is

To run encoding in a GPU, you have to compile Julia from source (I know this sucks! but it will no longer be necessary with Julia 1.0). You will also need to install

Finally, to run the sparse encoding demo you will need Matlab to run the SPGL1 solver by van den Berg and Friedlander, as well as the MATLAB.jl package to call Matlab functions from Julia.

Demos

First, clone this repository and download the SIFT1M dataset. To do so run the following commands:

git clone git@github.com:jltmtz/local-search-quantization.git
cd local-search-quantization
mkdir data
cd data
wget ftp://ftp.irisa.fr/local/texmex/corpus/sift.tar.gz
tar -xvzf sift.tar.gz
rm sift.tar.gz
cd ..

Also, compile the auxiliary search cpp code:

cd src/linscan/cpp/
./compile.sh
cd ../../../

For expedience, the following demos train on the first 10K vectors of the SIFT1M dataset. To reproduce the paper results you will have to use the full training set with 100K vectors.

There are 3 main functionalities showcased in this code:

1) Baselines and LSQ demo with encoding in the CPU

Simply run

julia demos/demo_pq.jl
julia demos/demo_opq.jl
julia demos/demo_lsq.jl

This will train PQ, OPQ, and LSQ on a subset of SIFT1M, encode the base set and compute a recall@N curve. To get better speed in LSQ, you can also run the code on parallel in multiple cores using

julia -p n demos/demo_lsq.jl

Where n is the number of CPU cores on your machine.

2) LSQ demo with encoding in the GPU

If you have a CUDA-enabled GPU, you might want to try out encoding in the GPU.

First, compile the CUDA code:

cd src/encodings/cuda
./compile.sh
cd ../../../

and then run

julia demos/demo_lsq_gpu.jl

or

julia -p n demos/demo_lsq_gpu.jl

Where n is the number of CPU cores on your machine.

3) LSQ demo with sparse encoding

This is very similar to demo #1, but the learned codebooks will be sparse.

First of all, you have to download the SPGL1 solver by van den Berg and Friedlander, and add the function that implements Expression 8 to the package

cd matlab
git clone git@github.com:mpf/spgl1.git
mv sparse_lsq_fun.m spgl1/
mv splitarray.m spgl1/
cd ..

Now you should be able to run the demo

julia -p n demos/demo_lsq_sparse.jl

Where n is the number of CPU cores on your machine.

Note that you need MATLAB installed on your computer to run this demo, as well as well as the MATLAB.jl package to call Matlab functions from Julia. Granted, getting all this to work can be a bit of a pain -- if at this point you (like me) love Julia more than any other language, please consider porting SPGL1 to Julia.

Citing

Thank for your interest in our research! If you find this code useful, please consider citing our paper

Julieta Martinez, Joris Clement, Holger H. Hoos, James J. Little. "Revisiting
additive quantization", ECCV 2016.

If you use our GPU implementation please consider citing

Julieta Martinez, Holger H. Hoos, James J. Little. "Solving multi-codebook
quantization in the GPU", 4th Workshop on Web-scale Vision and Social Media
(VSM), at ECCV 2016.

FAQ

Acknowledgments

Some of our evaluation code and our OPQ implementation has been adapted from Cartesian k-means by Mohamad Norouzi and optimized product quantization by Kaiming He.

License

MIT