QClusformer: A Quantum Transformer-based Framework for Unsupervised Visual Clustering

Xuan-Bac Nguyen, Hoang-Quan Nguyen, Samuel Yen-Chi Chen, Samee U. Khan, Hugh Churchill, Khoa Luu · DOI

Introduction

Unsupervised visual clustering—the process of grouping images without predefined labels—is a cornerstone of modern computer vision. However, as datasets scale into the millions, traditional algorithms such as K-means, Hierarchical Agglomerative Clustering (HAC), and DBSCAN face significant bottlenecks. These methods often become computationally prohibitive or suffer from memory constraints when processing high-dimensional data at scale.

While the Transformer architecture has revolutionized supervised vision tasks through its powerful self-attention mechanism, its application to massive-scale unsupervised clustering remains resource-intensive on classical hardware. QClusformer addresses this challenge by integrating Quantum Machine Learning (QML) into the Transformer pipeline. By leveraging quantum properties like superposition and entanglement, QClusformer aims to process complex visual relationships more efficiently than traditional classical bits, specifically targeting the constraints of the Noisy Intermediate-Scale Quantum (NISQ) era.

The QClusformer Framework

QClusformer utilizes a hybrid quantum-classical approach designed to maximize the strengths of both paradigms. The workflow is divided into four primary stages:

  1. Classical Pre-processing: The framework begins with a classical deep learning model that extracts feature vectors from raw images. To manage the initial search space, a k-Nearest Neighbor (k-NN) algorithm is employed to generate a coarse, initial clustering.
  2. Quantum State Encoding: To transition from classical data to quantum states, the model employs Amplitude Encoding. This technique is highly efficient, allowing a $D$-dimensional classical vector to be represented using only $n = \lceil \log_2(D) \rceil$ qubits. This logarithmic scaling is crucial for handling high-dimensional visual features with limited quantum memory.
  3. Quantum Self-Attention Module: The core innovation of QClusformer is its "single-circuit" self-attention mechanism. In a standard classical Transformer, Query ($Q$), Key ($K$), and Value ($V$) vectors are generated via three independent linear transformations. QClusformer replaces these with a single Parameterized Quantum Circuit (PQC). By measuring the output state against three distinct Pauli observables ($\sigma_x, \sigma_y, \sigma_z$), the model extracts $Q, K,$ and $V$ simultaneously. This significantly reduces the quantum resources required compared to using multiple circuits.
  4. Cosine Similarity Encoding: Unlike Natural Language Processing (NLP) which uses positional encodings, QClusformer uses a specialized encoding based on the cosine similarity between samples and the cluster center. This helps the model capture the internal structural relationships within a cluster more effectively.

Experimental Results

The researchers evaluated QClusformer against traditional clustering methods and a "Classical Clusformer" (an identical architecture using classical linear layers instead of PQCs) using two large-scale benchmarks: MS-Celeb-1M (5.8M images) and DeepFashion.

Performance and Scalability

On a subset of 584K images from MS-Celeb-1M, QClusformer achieved a Pairwise F1-score ($F_P$) of 74.50%. This performance notably surpassed the Classical Clusformer, which achieved 63.31%. While traditional K-means showed a higher initial $F_P$ on smaller subsets, its performance and feasibility degraded rapidly as the dataset size increased.

As the test set scaled to 5.21 million images, QClusformer demonstrated remarkable robustness, maintaining an $F_P$ of 68.38%. In contrast, the performance of classical methods like HAC and Approximate Rank-Order (ARO) collapsed to near zero or single digits at this scale, highlighting the scalability advantage of the quantum-enhanced approach.

Versatility

To ensure the model was not over-specialized for facial recognition, it was also tested on the DeepFashion dataset. QClusformer achieved the highest scores in this domain as well ($F_P$ of 35.71%), confirming its utility across diverse visual categories.

Discussion and Future Work

QClusformer represents a significant step toward practical quantum advantage in computer vision. By framing the Transformer as a "denoiser" that refines initial k-NN clusters, the authors demonstrate how quantum circuits can identify and remove misassigned samples more effectively than classical counterparts.

However, several limitations remain. Due to current hardware constraints, the experiments were conducted via quantum simulation, limiting the model to a single Transformer block ($T=1$). Furthermore, the system still relies on classical components for feature extraction and initial clustering. Future research will focus on developing end-to-end quantum pipelines and addressing the challenges of decoherence and hardware noise when transitioning from simulations to physical Quantum Processing Units (QPUs).

Summary updated

BibTeX
@inproceedings{nguyen2024qclusformer,
  author = {Xuan-Bac Nguyen and Hoang-Quan Nguyen and Samuel Yen-Chi Chen and Samee U. Khan and Hugh Churchill and Khoa Luu},
  title = {{QClusformer: A Quantum Transformer-based Framework for Unsupervised Visual Clustering}},
  booktitle = {QCE},
  year = {2024},
  doi = {10.1109/qce60285.2024.10304},
}
Figure