The image retrieval pipeline consists of several distinct steps:
We utilize a native PyTorch inference to generate the database and query sets for image retrieval. An example for performing retrieval on ImageNet-4K with an MRL pretrained model (trained with PyTorch DDP) is provided below:
python ../inference/pytorch_inference.py --retrieval --path=path_to_model/final_weights.pt \
--retrieval_array_path='output_path/' --dataset=1K --mrl
This will generate train (database) and val (query) arrays for the vector representations and labels for ImageNet-1K, ie
1K_val_mrl1_e0_ff2048-X.npy
, 1K_val_mrl1_e0_ff2048-y.npy
, 1K_train_mrl1_e0_ff2048-X.npy
, and 1K_train_mrl1_e0_ff2048-y.npy
, which will be saved to disk in the output_path/
directory.
The arrays generated above are used to create an index file of the database, as shown in faiss_nn.ipynb
. FAISS requires an
index type (Exact L2, HNSW32) and a shortlist length neighbors/mrl/exactl2_16dim_2048shortlist_1K.csv
.
In an attempt to achieve equivalent performance to shortlisting at higher representation sizes with reduced MFLOPs, we perform adaptive retrieval by, for example, retrieving a shortlist 8dim-reranked16_200shortlist_V2_exactl2.csv
as shown in reranking.ipynb
.
In an attempt to remove supervision in choosing
8dim-cascade[16,32,64,128,2048]_shortlist[200,100,50,25,10]_1K_exactl2.csv
We compute mAP@k, precision@k, recall@k, and top-k accuracy of the k-NN shortlist for various values of compute_metrics.ipynb
, with flags for model configuration, dataset, index type, and retrieval configuration required. The script loads database labels
1K_train_mrl1_e0_ff2048-y.npy
and query labels 1K_val_mrl1_e0_ff2048-y.npy
alongside the k-NN shortlist generated via FAISS retrieval
(neighbors/mrl/exactl2_16dim_2048shortlist_1K.csv
as in the example above) or
after reranking/funnel retrieval in the steps above.