Ternary Hashing

Chang Liu, Lixin Fan, Kam Woh Ng, Yilun Jin, Ce Ju, Tianyu Zhang, Chee Seng Chan, Qiang YangarXiv 2021

Abstract

Large-scale image retrieval often relies on binary hashing to compress high-dimensional features into compact bitstrings for efficient search. However, binary quantization forces a hard threshold that can lead to neighborhood ambiguity for features near the decision boundary. This paper introduces "Ternary Hashing," a novel scheme that incorporates a third "UNKNOWN" state to handle ambiguous data points. By leveraging formal ternary logic (Kleene and Łukasiewicz), the proposed method significantly reduces quantization error and improves retrieval accuracy (mAP) by up to 5.9% on standard benchmarks like ImageNet100.

Introduction

In the domain of large-scale image retrieval, binary hashing has long been the standard for balancing search speed and memory efficiency. By mapping complex image features into strings of 0s and 1s, similarity search is reduced to calculating Hamming distances. However, this binary approach suffers from significant quantization error. Features that fall near the decision threshold are assigned disparate codes despite being nearly identical in the original feature space, leading to "neighborhood ambiguity."

Methodology: From Bits to Trits

The proposed Ternary Hashing framework addresses this by introducing a third state—UNKNOWN (0)—alongside the traditional -1 and 1. This creates a buffer zone for ambiguous features.

Double-Threshold Mapping

Instead of a single split point, the system employs a double-thresholding strategy ($t^1$ and $t^2$). Values falling between these thresholds are assigned the neutral state 0. This mapping, $\phi_t(u, t^1, t^2)$, effectively downweights the importance of bits that were uncertain during encoding.

Overview of the Ternary Hashing pipeline and its effect on Hamming distance distributions.

Ternary Hamming Distance (THD)

To compare these ternary codes, the authors utilize axiomatic ternary logic, specifically Kleene and Łukasiewicz logic. These systems define operations like AND, OR, and EQUIVALENCE in the presence of a neutral state. Kleene logic, in particular, was found to be superior as it assigns a distance of 0.5 between two UNKNOWN states, avoiding overconfidence in ambiguous data.

Experimental Results

The effectiveness of ternary hashing was evaluated as a post-processing step across several deep hashing architectures, including HashNet and GreedyHash, using benchmarks such as CIFAR-10, NUS-WIDE, and ImageNet100.

Performance Gains

Ternary hashing consistently outperformed binary methods. The most notable improvements were observed on the ImageNet100 dataset, where mean Average Precision (mAP) increased by up to 5.9%, particularly for shorter code lengths (e.g., 16 bits).

mAP performance comparison on ImageNet100 across various deep hashing methods.

Efficiency and Separability

Visualization of Hamming distance distributions confirms that ternary hashing reduces the overlap between positive and negative sample histograms, enhancing the system's discriminative power. Furthermore, the Ternary Hamming Distance can be computed efficiently on binary hardware using bitwise XOR and OR operations, maintaining the speed advantages of traditional hashing.

Conclusion

Ternary Hashing provides a principled, logic-based framework for reducing quantization error in image retrieval. By embracing the "UNKNOWN" state, the method achieves significant accuracy boosts with minimal computational overhead. Future work includes integrating threshold optimization directly into end-to-end neural network training and exploring native ternary hardware implementations like FPGAs.

Summary updated

Abstract

This paper proposes a novel ternary hash encoding for learning to hash methods, which provides a principled more efficient coding scheme with performances better than those of the state-of-the-art binary hashing counterparts. Two kinds of axiomatic ternary logic, Kleene logic and {\L}ukasiewicz logic are adopted to calculate the Ternary Hamming Distance (THD) for both the learning/encoding and testing/querying phases. Our work demonstrates that, with an efficient implementation of ternary logic on standard binary machines, the proposed ternary hashing is compared favorably to the binary hashing methods with consistent improvements of retrieval mean average precision (mAP) ranging from 1\% to 5.9\% as shown in CIFAR10, NUS-WIDE and ImageNet100 datasets.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
CIFAR-10 · CIFAR10Ternary hashing with Kleene logic applied to GreedyHash (GH-16)retrieval mAP0.825+0.01 vs baselinelogic=Kleene · bin_size=100 · code_length=16
Source quote
L263: GH-16 │ 0.815 │ 0.820 │ 0.825 │ 0.730 │ 0.786 │ 0.768 │ 0.584 │ 0.609 │ 0.621
NUS-WIDETernary hashing with Kleene logic applied to GreedyHash (GH-16)retrieval mAP0.768+0.04 vs baselinelogic=Kleene · subset=21 most frequent concepts · bin_size=100 · code_length=16
Source quote
L263: GH-16 │ 0.815 │ 0.820 │ 0.825 │ 0.730 │ 0.786 │ 0.768 │ 0.584 │ 0.609 │ 0.621
Reported baseline / comparator measurements (2)
BenchmarkMethodMetricScoreProtocol / Evidence
CIFAR-10 · CIFAR10GreedyHash (GH-16), binary hashing baselineretrieval mAP0.815bin_size=100 · code_length=16
Source quote
L263: GH-16 │ 0.815 │ 0.820 │ 0.825 │ 0.730 │ 0.786 │ 0.768 │ 0.584 │ 0.609 │ 0.621
NUS-WIDEGreedyHash (GH-16), binary hashing baselineretrieval mAP0.730subset=21 most frequent concepts · bin_size=100 · code_length=16
Source quote
L263: GH-16 │ 0.815 │ 0.820 │ 0.825 │ 0.730 │ 0.786 │ 0.768 │ 0.584 │ 0.609 │ 0.621
BibTeX
@misc{liu2021ternary,
  author = {Chang Liu and Lixin Fan and Kam Woh Ng and Yilun Jin and Ce Ju and Tianyu Zhang and Chee Seng Chan and Qiang Yang},
  title = {{Ternary Hashing}},
  year = {2021},
  eprint = {2103.09173},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2103.09173},
}
Figure