Supervised Learning of Semantics-Preserving Deep Hashing (SSDH)
Created by Kevin Lin, Huei-Fang Yang, and Chu-Song Chen at Academia Sinica, Taipei, Taiwan.
We present a simple yet effective supervised deep hash approach that constructs binary hash codes from labeled data for large-scale image search. SSDH constructs hash functions as a latent layer in a deep network and the binary codes are learned by minimizing an objective function defined over classification error and other desirable hash codes properties. Compared to state-of-the-art results, SSDH achieves 26.30% (89.68% vs. 63.38%), 17.11% (89.00% vs. 71.89%) and 19.56% (31.28% vs. 11.72%) higher precisions averaged over a different number of top returned images for the CIFAR-10, NUS-WIDE, and SUN397 datasets, respectively.
The details can be found in the following arXiv preprint. Presentation slide can be found here
If you find our work useful in your research, please consider citing:
Supervised Learning of Semantics-Preserving Hashing via Deep Neural Networks for Large-Scale Image Search
Huei-Fang Yang, Kevin Lin, Chu-Song Chen
arXiv preprint arXiv:1507.00101
- MATLAB (tested with 2012b on 64-bit Linux)
- Caffe's prerequisites
Adjust Makefile.config and simply run the following commands:
$ make all -j8
$ make test -j8
$ make matcaffe
$ ./prepare.sh
For a faster build, compile in parallel by doing make all -j8 where 8 is the number of parallel threads for compilation (a good choice for the number of threads is the number of cores in your machine).
Launch matlab and run demo.m. This demo will generate 48-bits binary codes for each image using the proposed SSDH.
>> demo
Launch matalb and run run_cifar10.m to perform the evaluation of precision at k and mean average precision at k. We set k=1000 in the experiments. The bit length of binary codes is 48. This process takes around 12 minutes.
>> run_cifar10
Then, you will get the mAP result as follows.
>> MAP = 0.897165
Moreover, simply run the following commands to generate the precision at k curves:
$ cd analysis
$ gnuplot plot-p-at-k.gnuplot
You will reproduce the precision curves with respect to different number of top retrieved samples when the 48-bit hash codes are used in the evaluation.
Simply run the following command to train SSDH:
$ cd /examples/SSDH
$ ./train.sh
After 50,000 iterations, the top-1 error is around 10% on the test set of CIFAR10 dataset:
I1109 20:36:30.962478 25398 solver.cpp:326] Iteration 50000, loss = -0.114461
I1109 20:36:30.962507 25398 solver.cpp:346] Iteration 50000, Testing net (#0)
I1109 20:36:45.218626 25398 solver.cpp:414] Test net output #0: accuracy = 0.8979
I1109 20:36:45.218660 25398 solver.cpp:414] Test net output #1: loss: 50%-fire-rate = 0.0005225 (* 1 = 0.0005225 loss)
I1109 20:36:45.218668 25398 solver.cpp:414] Test net output #2: loss: classfication-error = 0.368178 (* 1 = 0.368178 loss)
I1109 20:36:45.218675 25398 solver.cpp:414] Test net output #3: loss: forcing-binary = -0.114508 (* 1 = -0.114508 loss)
I1109 20:36:45.218682 25398 solver.cpp:331] Optimization Done.
I1109 20:36:45.218686 25398 caffe.cpp:214] Optimization Done.
The training process takes roughly 2~3 hours on a desktop with Titian X GPU. You will finally get your model named SSDH48_iter_xxxxxx.caffemodel under folder /examples/SSDH/
To use the model, modify the model_file in demo.m to link to your model:
model_file = './YOUR/MODEL/PATH/filename.caffemodel';
Launch matlab, run demo.m and enjoy!
>> demo
It should be easy to train the model using another dataset as long as that dataset has label annotations.
- Convert your training/test set into leveldb/lmdb format using
create_imagenet.sh. - Modify the
sourcein/example/SSDH/train_val.prototxtto link to your training/test set. - Run
./examples/SSDH/train.sh, and start training on your dataset.
Note: This documentation may contain links to third party websites, which are provided for your convenience only. Third party websites may be subject to the third party’s terms, conditions, and privacy statements.
If ./prepare.sh fails to download data, you may manually download the resouces from:
Please feel free to leave suggestions or comments to Kevin Lin ([email protected]), Huei-Fang Yang ([email protected]) or Chu-Song Chen ([email protected])

