中文 | English
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.
- 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
- Clone the repository:
git clone https://github.com/zheng0116/ImageRetrieval.git
cd ImageRetrieval
- Install dependencies:
sh run.sh install
- Download the Dinov2 weights:
https://pan.baidu.com/s/1fBVgg_o8PTFEu_2vtLY25Q
Extraction code: f9ww
- 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"
-
Prepare your image database by placing images in the
quary
folder (or specify a custom folder in .env). -
Run the application:
sh run.sh start
-
Open a web browser and navigate to
http://localhost:5999
. -
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"
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")
main.py
: Main application file with FastAPI serverretrieval/model/Diniv2.py
: DINOv2 model loaderretrieval/model/clip_model.py
: CLIP model loaderretrieval/services/utils/image_process.py
: Image preprocessingretrieval/retrieval.py
: Image retrieval logicstatic/index.html
: Web interface
- Python 3.7+
- FastAPI
- Uvicorn
- PyTorch
- Transformers
- Pillow
- NumPy
- tqdm