Faiss cpuバージョンインストール記

2560 ワード

仕事のため、一時的にFaissを知ったのは、似たような図を探すのに良いツールだという.ここでは主にcpuバージョンをインストールする過程を記録している.主にreference 1を参照した.
開発環境の紹介
centosシステム、64ビットfaiss公式も64ビットシステムでテストされているので、32ビットシステムが互換性があるかどうか分かりません.
Anacondaのインストール
AnacondaはPythonの科学計算ツールパッケージです.Python 2とPython 3のサポートにより、Anaconda 2とAnaconda 3に分けられます.公式サイトは最新のバージョンを提供しており、その他のバージョンは清華大学オープンソースソフトウェアミラーステーションでダウンロードすることができます.本人が慣れているのでpython 2を選びました
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda2-4.3.0-Linux-x86_64.sh
#     
chmod +x Anaconda2-4.3.0-Linux-x86_64.sh
#       ,  Enter 。
bash Anaconda2-4.3.0-Linux-x86_64.sh
#   1
conda list 
   N Python   
#   2
python --version
   Anaconda   Python,  :
Python 2.7.13 :: Anaconda custom (64-bit)

Openblasのインストール
実際、mklがサポートするFAISSが最も効率的ですが、著作権認証などの問題でopenblasを選択しました.
# Anaconda2    openblas。
conda install openblas
# root       。
ln -s $HOME/anaconda2/lib/libopenblas.so.0 /usr/lib64/libopenblas.so.0

FAISSのインストール
#   FAISS  .
git clone https://github.com/facebookresearch/faiss.git
#   FAISS    .
cd faiss
#           . [Linux   ]
cp example_makefiles/makefile.inc.Linux ./makefile.inc
#    &  BLAS  .
make tests/test_blas
./tests/test_blas

C++開発環境の構成
#     .
make
# 5.1、    .
#       .
./tests/demo_ivfpq_indexing
# 5.2、    .
#      .
wget ftp://ftp.irisa.fr/local/texmex/corpus/sift.tar.gz
tar -xzvf sift.tar.gz
#      。
mv sift sift1M
#    &      .
make tests/demo_sift1M
./tests/demo_sift1M

python開発環境の構成
#       
vim makefile.inc
   PYTHONCFLAGS   ,    :
PYTHONCFLAGS=-I$HOME/anaconda2/include/python2.7/ -I$HOME/anaconda2/lib/python2.7/site-packages/numpy/core/include/
#   .
make py
#    python-faiss.
python -c "import faiss"
ldd -r _swigfaiss.so
# 6.1、    .
python -c "import faiss, numpy
faiss.Kmeans(10, 20).train(numpy.random.rand(1000, 10).astype('float32'))"
# 6.2、    .
export PYTHONPATH=.
mkdir tmp
python python/demo_auto_tune.py

trouble shooting
python開発環境の構成中に次のエラーが発生しました.
#       
make py
#       
make: *** [python/_swigfaiss.so] Error 1

その後faissの公式サイトで以下の解答を見つけました.
cd faiss/python
#      swig       ,    
git checkout swigfaiss_gpu_wrap.cxx swigfaiss_gpu.py swigfaiss_wrap.cxx swigfaiss.py
#        ,     
make py

Reference
  • http://blog.csdn.net/u010641294/article/details/72783372
  • https://github.com/facebookresearch/faiss/wiki/Troubleshooting