This project is forked from plippe/faiss-web-service .
Then I add three new feature:
- Image feature extraction
- Build Faiss index
- Build docker which can run Faiss.
For more detail info about Faiss and this project, you can check my blog.
This project use SIFT of OpenCv, code location is: src/utils/feature_detect.py
.
Code location:src/train_index/train_index.py
.
This type index doesn't need train.
In the real world, we may use the index which need pre-train, such as "IVFx,Flat".
About how to choose what type index you need, you can refer here.
Code location:src/train_index/train_index_with_pre_train.py
.
If you think the output dimension of SIFT (default is 128) is too low, you can use the Bag of Words.
Code location:src/train_index/train_index_bow.py
。
Code location:src/train_index/train_index_from_java.py
。
I have install Opencv 3.2 for extract feature base on original docker image. You can go the docker hub image download base image:
docker pull waltyou/faiss-api-service:1.2.1-gpu
Start docker container:
cd src/train_index
python train_index.py
# Faiss search for ids 1, 2, and 3
curl 'localhost:5000/faiss/search' -X POST -d '{"k": 5, "ids": [1, 2, 3]}'
# Faiss search for image path
curl 'localhost:5000/faiss/search' -X POST -d '{"k": 5, "image": “/image/path/imagename”}'
# Faiss search for vector file path
curl 'localhost:5000/faiss/search' -X POST -d '{"k": 5, "vectors": “/vector/file/path”}'
Go into docker container , and run bin/faiss_web_service.sh
.
Check if container is ok:
# Healthcheck
curl 'localhost:5000/ping'