🌷 PromptHash: Affinity-Prompted Collaborative Cross-Modal Learning for Adaptive Hashing Retrieval [CVPR 2025]

June 24, 2025 Β· View on GitHub

Overview 🌟

PromptHash (Affinity-Prompted Collaborative Cross-Modal Learning for Adaptive Hashing Retrieval) is a method for adaptive hashing retrieval through collaborative cross-modal learning.
This repository contains the code associated with the paper:

"PromptHash: Affinity-Prompted Collaborative Cross-Modal Learning for Adaptive Hashing Retrieval" (accepted to CVPR 2025)
Qiang Zou, Shuli Chengβœ‰οΈ, and Jiayi Chen


Usage πŸ› οΈ

  1. Clone the repository

    git clone https://github.com/ShiShuMo/PromptHash.git
    cd PromptHash
    
  2. Create and activate the environment

    conda create -n prompthash python=3.12 -y
    conda activate prompthash
    
  3. Install dependencies

    # Install PyTorch 2.7.1
    pip3 install torch==2.7.1 torchvision==0.22.1 torchaudio==2.7.1 --index-url https://download.pytorch.org/whl/cu128
    
    # Install mamba_ssm
    # See: https://github.com/state-spaces/mamba
    # For CUDA 12.8, download pre-built .whl from the release page
    
    # Install causal-conv1d
    # See: https://github.com/Dao-AILab/causal-conv1d
    # For CUDA 12.8, download pre-built .whl from the release page
    

Data πŸ—‚οΈ

Directory Structure:

dataset
β”œβ”€β”€ coco
β”‚   β”œβ”€β”€ caption.mat
β”‚   β”œβ”€β”€ prompt_caption.npz 
β”‚   β”œβ”€β”€ index.mat
β”‚   └── label.mat 
β”œβ”€β”€ flickr25k
β”‚   β”œβ”€β”€ caption.mat
β”‚   β”œβ”€β”€ prompt_caption.npz
β”‚   β”œβ”€β”€ index.mat
β”‚   └── label.mat
β”œβ”€β”€ nuswide
β”‚   β”œβ”€β”€ caption.txt
β”‚   β”œβ”€β”€ prompt_caption.npz
β”‚   β”œβ”€β”€ index.mat 
β”‚   └── label.mat
  • Please preprocess the datasets to the required input format.
  • All .mat files have already been uploaded in the ./dataset directory. Use the unzip command to extract them.
  • Cleaned datasets (MIRFLICKR25K, MSCOCO, NUSWIDE), including all files required for experiments, are available via Baidu Netdisk.

πŸ”— Baidu Netdisk Download
Password: kdq7

(Source: CMCL)


About prompt_caption.npz πŸ“

The prompt_caption.npz file for each dataset contains:

  • Pseudo-label embeddings generated by large language models.
  • Template sentence embeddings for each dataset sample.

These files are generated and preprocessed for direct use in training and evaluation.
You do not need to generate them yourself.
The prompt_caption.npz files are included in the Baidu Netdisk dataset below.

πŸ”— Baidu Netdisk Download
Password: krua


Training πŸ‹οΈβ€β™‚οΈ

After preparing the Python environment, pretrained MetaCLIP model, and dataset, you can train the PromptHash model.

  • The script will automatically download the required weights. Ensure your network connection is stable.
  • See PromptHash_$DATASET$.sh for training scripts.
  • For hyperparameter settings, refer to the paper.

Evaluation πŸ“Š

  • See PromptHash_$DATASET$_TEST.sh for evaluation scripts.
  • Hash code files generated by our algorithm are included in the repository (test.zip), which can be used directly for verification.

Citation πŸ“œ

If you find the PromptHash paper and code useful for your research and applications, please cite using this BibTeX:

@InProceedings{Zou_2025_CVPR,
    author    = {Zou, Qiang and Cheng, Shuli and Chen, Jiayi},
    title     = {PromptHash: Affinity-Prompted Collaborative Cross-Modal Learning for Adaptive Hashing Retrieval},
    booktitle = {Proceedings of the Computer Vision and Pattern Recognition Conference (CVPR)},
    month     = {June},
    year      = {2025},
    pages     = {19649-19658}
}

Any Question βœ‰οΈ

If you have any questions, please feel free to contact:


Acknowledgements 🌸

This project is based on open_clip and CMCL β€” special thanks to all contributors.