Vector search finds wide applications in image recognition and image retrieval. It aims to obtain the similarity ranking for a given query vector by performing a similarity or distance calculation of feature vectors with all the vectors to be queried in an established vector library. In the image recognition system, Faiss is adopted for corresponding support, please check the official website of Faiss for more details. The main advantages of Faiss
can be generalized as the following:
python
interface and direct installation with pip
It is worth noting that the current version of PaddleClas
only uses CPU for vector retrieval for the moment in pursuit of better adaptability.
As shown in the figure above, two parts constitute the vector search in the whole PP-ShiTu
system.
This document mainly introduces the installation of the search module in PaddleClas, the adopted search algorithms, the library building process, and the parameters in the relevant configuration files.
Faiss
can be installed as follows:
pip install faiss-cpu==1.7.1post2
If the above cannot be properly used, please uninstall
and then install
again, especially when you are usingwindows
.
Currently, the search module in PaddleClas
supports the following three search algorithms:
Each search algorithm can find its right place in different scenarios. HNSW32
, as the default method, strikes a balance between accuracy and speed, see its detailed introduction in the official document.
Configuration files involving the search module are under deploy/configs/
, where build_*.yaml
is related to building the feature library, and inference_*.yaml
is the inference file for retrieval or classification.
The building of the library is detailed as follows:
# Enter deploy directory
cd deploy
# Change the yaml file to the specific one you need
python python/build_gallery.py -c configs/build_***.yaml
The yaml
file is configured as follows for library building, please make necessary corrections to fit the real operation. The construction will extract the features of the images under image_root
according to the image list in data_file
and store them under index_dir
for subsequent search.
The data_file
stores the path and label of the image file, with each line presenting the format image_path label
. The intervals are spaced by the delimiter
parameter in the yaml
file.
The specific model parameters for feature extraction can be found in the yaml
file.
# indexing engine config
IndexProcess:
index_method: "HNSW32" # supported: HNSW32, IVF, Flat
index_dir: "./recognition_demo_data_v1.1/gallery_product/index"
image_root: "./recognition_demo_data_v1.1/gallery_product/"
data_file: "./recognition_demo_data_v1.1/gallery_product/data_file.txt"
index_operation: "new" # suported: "append", "remove", "new"
delimiter: "\t"
dist_type: "IP"
embedding_size: 512
new
for initiating an operation, append
for adding the image feature of data_file to the feature library, remove
for deleting the image of data_file from the feature library.IP
) and Euclidean distance(L2
).To integrate the search into the overall PP-ShiTu
process, please refer to The Introduction of PP-ShiTu Image Recognition System
in README. Please check the Quick Start for Image Recognition for the specific operation of the search.
The search part is configured as follows. Please refer to deploy/configs/inference_*.yaml
for the complete version.
IndexProcess:
index_dir: "./recognition_demo_data_v1.1/gallery_logo/index/"
return_k: 5
score_thres: 0.5
The following are new parameters other than those of the library building configuration file:
return_k
: k
results are returnedscore_thres
: the threshold for retrieval and match此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。