An Open-Source Package for Deep Learning to Hash (DeepHash)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
DeepHash fix bug for dch Aug 31, 2018
data fix bug with coco image path Sep 2, 2018
examples add data_root option && add sample data_list Aug 31, 2018
.gitignore update dtq Apr 21, 2018
LICENSE first version Apr 20, 2018
requirements.txt first version Apr 20, 2018


DeepHash is a lightweight deep learning to hash library that implements state-of-the-art deep hashing/quantization algorithms. We will implement more representative deep hashing models continuously according to our released deep hashing paper list. Specifically, we welcome other researchers to contribute deep hashing models into this toolkit based on our framework. We will announce the contribution in this project.

The implemented models include:

Note: DTQ and DCH are updated while DQN, DHN, DVSQ maybe outdated, feel free to touch us if you have any questions. We welcome others to contribute!


  • Python3: Anaconda is recommended because it already contains a lot of packages:
conda create -n DeepHash python=3.6 anaconda
source activate DeepHash
  • Other packages:
conda install -y tensorflow-gpu
conda install -y -c conda-forge opencv

To import the pakcages implemented in ./DeepHash, we need to add the path of ./DeepHash to environment variables as:

export PYTHONPATH=/path/to/project/DeepHash/DeepHash:$PYTHONPATH

Data Preparation

In data/cifar10/train.txt, we give an example to show how to prepare image training data. In data/cifar10/test.txt and data/cifar10/database.txt, the list of testing and database images could be processed during predicting procedure. If you want to add other datasets as the input, you need to prepare train.txt, test.txt and database.txt as CIFAR-10 dataset.

What's more, We have put the whole cifar10 dataset including the images and data list in the release page. You can directly download it and unzip to data/cifar10 folder.

Make sure the tree of /path/to/project/data/cifar10 looks like this:

|-- database.txt
|-- test
|-- test.txt
|-- train
`-- train.txt

If you need run on NUSWIDE_81 and COCO, we recommend you to follow to prepare NUSWIDE_81 and COCO images.

For DVSQ model, you also need the word vector of the semantic labels. Here we use word2vec model pretrained on GoogleNews Dataset (e.g., to extract the word embeddings for the labels of images, e.g. dog, cat and so on.

Get Started

Pre-trained model

You should manually download the model file of the Imagenet pre-tained AlexNet from here or from release page and unzip it to /path/to/project/DeepHash/architecture/pretrained_model.

Make sure the tree of /path/to/project/DeepHash/architecture looks like this:

├── pretrained_model
       └── reference_pretrain.npy

Training and Testing

The example of $method (DCH and DTQ) can be run like:

cd example/$method/
python --gpus "0,1" --data-dir $PWD/../../data --"other parameters descirbe in"

For DVSQ, DQN and DHN, please refer to the and in the examples folder.


If you find DeepHash is useful for your research, please consider citing the following papers:

  Author = {Yue Cao and Mingsheng Long and Jianmin Wang and Han Zhu and Qingfu Wen},
  Publisher = {AAAI},
  Title = {Deep Quantization Network for Efficient Image Retrieval},
  Year = {2016}

  Author = {Han Zhu and Mingsheng Long and Jianmin Wang and Yue Cao},
  Publisher = {AAAI},
  Title = {Deep Hashing Network for Efficient Similarity Retrieval},
  Year = {2016}

  Title={Deep visual-semantic quantization for efficient image retrieval},
  Author={Cao, Yue and Long, Mingsheng and Wang, Jianmin and Liu, Shichen},

  Title={Deep Cauchy Hashing for Hamming Space Retrieval},
  Author={Cao, Yue and Long, Mingsheng and Bin, Liu and Wang, Jianmin},

  title={Deep triplet quantization},
  author={Liu, Bin and Cao, Yue and Long, Mingsheng and Wang, Jianmin and Wang, Jingdong},
  journal={MM, ACM},


Maintainers of this library: