This is my project built for the Content-based Image Retrieval problem. In this project, I use the algorithm of indexing and searching Faiss (Facebook). Simultaneously combine many feature extraction methods for comparison and evaluation (RGBHistogram, Local Binary Pattern, VGG16, ResNet50).
Problem
- Input: A collection of information resources (image database), a query image
- Output: A ranked list of images that are most similar to the query image, with the most similar image at the top of the list
I use the faiss library created by Facebook. The weights of the VGG16 and Resnet50 networks are taken from the pre-trained model of torchvision.models.
-
python==3.8.16
-
Install PyTorch-cuda==11.7 following official instruction:
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
-
Install Facebook faiss:
conda install -c conda-forge faiss-gpu
-
Install the necessary dependencies by running:
pip install -r requirements.txt
-
Put the downloaded The Paris Dataset (or link Kaggle) in ./data/paris
-
Put the downloaded groundtruth in ./data/groundtruth
Please organize your dataset following this structure:
Main-folder/
│
├── dataset/
│ ├── evaluation
| | ├── crop
| | | ├── LBP
| | | | ├── defense_1.txt
| | | | ├── eiffel_1.txt
| | | | └── ...
| | | ├── Resnet50
| | | | └── ...
| | | ├── RGBHistogram
| | | | └── ...
| | | └── VGG16
| | | └── ...
| | └── original
| | └── ...
| |
│ ├── feature
| | ├── LBP.index.bin
| | ├── Resnet50.index.bin
| | ├── RGBHistogram.index.bin
| | └── VGG16.index.bin
| |
| ├── groundtruth
| | ├── defense_1_good.txt
| | ├── eiffel_4_query.txt
| | └── ...
| |
| └── paris
| ├── paris_defense_000000.jpg
| ├── paris_defense_000042.jpg
| └── ...
|
└── ...
python indexing.py --feature_extractor Resnet50
The Resnet50.index.bin file will be at Main-folder/dataset/feature.
Evaluation on query set
python ranking.py --feature_extractor Resnet50
python evaluate.py --feature_extractor Resnet50
streamlit run demo.py
You can modify the config like feature_extractor (RGBHistogram, LBP, VGG16, Resnet50), batch_size, top_k, ...