towhee.functional.mixins.faiss.FaissMixin¶
- class towhee.functional.mixins.faiss.FaissMixin[source]¶
Bases:
object
Mixins for Faiss, such as loading data into Faiss. And ids and vectors need to be passed as index. If ids is a string, KV storage will be started, and the kv data will be saved to the specified directory as “kv.bin”.
- Parameters:
findex (str or faiss.INDEX, optional) – The path to faiss index file(defaults to ‘./index.bin’) or faiss index.
string (str, optional) – A string to produce a composite Faiss index, which is the same parameter in faiss.index_factor, defaults to ‘IDMap,Flat’, and you can refer to https://github.com/facebookresearch/faiss/wiki/The-index-factory.
metric (faiss.METRIC, optional) – The metric for Faiss index, defaults to faiss.METRIC_L2.
- Returns:
A DC, and will save the Faiss index file and kv file(if ids is string).
Examples:
Note
Please make sure the path to index_file is authorized, and it will write the Faiss index file and kv file(if ids is string).
>>> import towhee >>> dc = ( ... towhee.glob['path']('./*.jpg') ... .image_decode['path', 'img']() ... .image_embedding.timm['img', 'vec'](model_name='resnet50') ... .to_faiss['path', 'vec'](findex='./faiss/faiss.index') ... )
Methods