Skip to content

This project is an image retrieval system based on DINOv2 and CLIP models, supporting both image-to-image and text-to-image retrieval. Users can upload an image or input text description to retrieve similar images from a predefined image database.

License

Notifications You must be signed in to change notification settings

zheng0116/ImageRetrieval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Retrieval System

中文 | English

🌟 Introduction

This project is an image retrieval system based on DINOv2 and CLIP models, supporting both image-to-image and text-to-image retrieval. Users can upload an image or input text description to retrieve similar images from a predefined image database.

🚀 Features

  • Image feature extraction using the DINOv2 model for image-to-image search
  • Text-to-image search powered by CLIP model
  • Support for different sizes of DINOv2 models (small, base, large, giant)
  • Image retrieval based on cosine similarity
  • Web interface built with FastAPI
  • Feature caching for large-scale image databases

User Interface

DINOv2 Image Retrieval System Interface

Installation

  1. Clone the repository:
git clone https://github.com/zheng0116/ImageRetrieval.git
cd ImageRetrieval
  1. Install dependencies:
sh run.sh install
  1. Download the Dinov2 weights:
https://pan.baidu.com/s/1fBVgg_o8PTFEu_2vtLY25Q
Extraction code: f9ww
  1. Configure environment variables: Create a .env file in the root directory with the following content:
SERVER_URL="0.0.0.0"
SERVER_PORT=5999
MODEL_PATH="./Dinov2_model/dinov2-small"
MODEL_SIZE="small"
DATABASE_FOLDER="./quary"

Usage

  1. Prepare your image database by placing images in the quary folder (or specify a custom folder in .env).

  2. Run the application:

sh run.sh start
  1. Open a web browser and navigate to http://localhost:5999.

  2. Search Methods:

    • Image-to-Image: Upload an image and click "Start Search"
    • Text-to-Image: Enter text description in the search box and click "Text Search"

Configuration

You can configure the following parameters in your .env file:

  • SERVER_URL: Server IP address (default: "0.0.0.0")
  • SERVER_PORT: Server port number (default: 5999)
  • MODEL_PATH: Path to the DINOv2 model (default: "./Dinov2_model/dinov2-small")
  • MODEL_SIZE: Size of the DINOv2 model (choices: small, base, large, giant; default: small)
  • DATABASE_FOLDER: Path to the image database folder (default: "./quary")

Project Structure

  • main.py: Main application file with FastAPI server
  • retrieval/model/Diniv2.py: DINOv2 model loader
  • retrieval/model/clip_model.py: CLIP model loader
  • retrieval/services/utils/image_process.py: Image preprocessing
  • retrieval/retrieval.py: Image retrieval logic
  • static/index.html: Web interface

Requirements

  • Python 3.7+
  • FastAPI
  • Uvicorn
  • PyTorch
  • Transformers
  • Pillow
  • NumPy
  • tqdm

License

MIT License

Acknowledgements

About

This project is an image retrieval system based on DINOv2 and CLIP models, supporting both image-to-image and text-to-image retrieval. Users can upload an image or input text description to retrieve similar images from a predefined image database.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published