This repository contains an implementation of an image retrieval system designed to search for and rank similar object in images from a large gallery based on query images. The system leverages CNN-based feature extraction to enhance retrieval performance. It is built to process a gallery of images and return ranked results based on similarity to a given query.
- A CNN-based approach using a pre-trained ResNet50 model for feature extraction, paired with cosine similarity for ranking.
- Modular Design: Code is organized into separate folders for each method, making it easy to extend or modify.
extract_feature_multi_process.py: Feature extraction using ResNet50.all_retrieval.py: Image retrieval and ranking using cosine similarity.
This method extracts deep features from images using a pre-trained ResNet50 model and ranks gallery images based on cosine similarity.
- Feature Extraction:
- Images are pre-processed (BGR to RGB conversion) using OpenCV.
- Objects are cropped using a Fast R-CNN model when multiple instances are present.
- ResNet50 extracts features after removing the fully connected layer, followed by global average pooling to generate a 1D feature vector.
- Retrieval:
- Cosine similarity is computed between the query feature vector and gallery feature vectors.
- Top 10 images with the highest similarity scores are returned.
- Python 3.x
- Libraries: OpenCV, NumPy, PyTorch (for ResNet50), and other dependencies (see
requirements.txtif provided). - A gallery of images (not included in this repo).
- Clone the repository:
git clone https://github.com/yourusername/image-retrieval-system.git cd image-retrieval-system - Install dependencies:
pip install -r requirements.txt
- Add your gallery images to the
gallery/folder and query images to thequery/folder.
- For CNN-based retrieval:
python /extract_feature_multi_process.py python /all_retrieval.py
- The
gallery/folder is empty to save space. Populate it with your image dataset before running the code. - Query images and bounding box annotations (if required) should be placed in the
query/folder. - Adjust file paths in the scripts if your dataset structure differs.
