Git Product home page Git Product logo

local-search-quantization's Introduction

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

  • CUDAdrv -- the CUDA driver API
  • CUBLAS -- for fast matrix multiplication in the GPU
  • A CUDA-enabled GPU with compute capability 3.5 or higher. We have tested our code on K40 and Titan X GPUs

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 [email protected]: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 [email protected]: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

  • Q: What is ChainQ?

    A: ChainQ is a quantization method inspired by optimized tree quantization (OTQ). Instead of learning the dimension splitting and sharing among codebooks (which OTQ finds using Gurobi), we simply take the natural splitting and sharing given by contiguous dimensions. Therefore, our codebooks form a chain, not a general tree. This means we can solve encoding optimally using the Viterbi algorithm.

  • Q: LSQ is very slow...?

    A: Compared to PQ and OPQ yes, but (a) it gives much better compression rates, and (b) it is much better in quality and speed compared to additive quantization (AQ) (our most similar baseline). The authors have made the AQ code available, so you can compare yourself :)

  • Q: The code does not reproduce the results of the paper...?

    A: The demos train on 10K vectors and for 10 iterations. To reproduce the results of the paper, train with the whole 100K vectors and do it for 100 iterations. You can also control the number of ILS iterations to use for database encoding in the LSQ demos; which corresponds to LSQ-16 and LSQ-32 in the paper.

  • Q: Why do I see all those warnings when I run your code?

    A: Julia 0.5 issues a warning when a method is redefined more than once in the Main scope. This is annoying for many people and will disappear in Julia 0.6 (see JuliaLang/julia#18725)

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

local-search-quantization's People

Contributors

una-dinosauria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

local-search-quantization's Issues

Support for Julia 0.6.0

Julia 6.0 is out with a number of potentially breaking changes. Let's try to bring this code up to speed.

Recall on SIFT1M under 32 bits is low

Hi,

Thanks for sharing the code. Recently I am running comparison experiments.

It works well under 64 bits and 128 bits and the results are comparable with LSQ paper. But under 32 bits, the recall is lower than ckmeans. Although LSQ paper didn't have results for 32 bits, can you please check the results for me? Or is there anything I missed?

recalls under 32 bits:
r@1 = 5.09%
r@10 = 23.53%
r@100 = 62.44%

I changed the hyperparameter npert from 4 to 3, 2, and 1, but similar results are obtained.

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.