Papers
Topics
Authors
Recent
Search
2000 character limit reached

CountCluster: Dual Clustering Methods

Updated 8 July 2026
  • CountCluster is a dual-purpose approach: one variant recovers unknown clusters via adaptive same-cluster queries, while the other partitions attention maps to match specified counts.
  • The interactive clustering method employs D²-sampling, rejection sampling, and oracle queries to incrementally identify clusters without presetting the cluster number.
  • The text-to-image variant refines early cross-attention maps using Gaussian smoothing and KL-loss minimization to guide object count accuracy in generated images.

CountCluster denotes two distinct methods in the literature, both centered on quantity determination through clustering but operating in different problem domains. In interactive clustering, CountCluster is the name of two algorithms for discovering and counting an unknown number of ground-truth clusters in a point set XRdX\subset\mathbb{R}^d by issuing same-cluster queries to an oracle (Li et al., 2021). In text-to-image generation, CountCluster is a training-free inference-time method that guides an object cross-attention map to be partitioned into kk spatially separated regions matching the object count specified in a prompt (Lee et al., 14 Aug 2025). The shared name reflects a common emphasis on recovering or enforcing discrete multiplicity, but the two methods differ fundamentally in assumptions, observables, optimization targets, and theoretical framing.

1. Scope and research context

The need to determine the number of clusters arises across several lines of work. In classical text clustering, the central issue is that many clustering algorithms require the number of clusters to be specified apriori; one response is to vary kk and monitor cluster quality measures such as entropy and purity until they stabilize (Grace et al., 2015). Another line uses a cluster ensemble to build a consensus similarity matrix and then identifies the true cluster count from a Perron cluster of eigenvalues near 1 in an associated random-walk matrix, with iterative refinement for noisy or high-dimensional data (Race et al., 2014). A further alternative targets heavily overlapping mixtures by introducing a quantum path-integral formulation in which interference suppresses spurious merged modes and reveals the number of clusters KK from peaks in Pq(y)P_q(y) (Muthyala et al., 2020).

Within this broader landscape, the CountCluster algorithms of "Learning to Cluster via Same-Cluster Queries" remove two assumptions that are common in earlier work: they do not assume that the total number of clusters is known at the beginning and do not require that the true clusters are consistent with a predefined objective function such as the K-means (Li et al., 2021). The CountCluster method of "Training-Free Object Quantity Guidance with Cross-Attention Map Clustering for Text-to-Image Generation" addresses a different counting problem: diffusion models often fail to generate images that accurately reflect the number of objects specified in the input prompt, and the method exploits the observation that the number of object instances is largely determined in the early timesteps of the denoising process (Lee et al., 14 Aug 2025).

CountCluster usage Domain Core mechanism
CountCluster Learning to cluster Same-cluster queries, D2D^2-sampling, centroid recovery
CountCluster Text-to-image generation Cross-attention map clustering, KL loss, latent refinement

This suggests that "CountCluster" is not a single unified framework but a reused name for two technical programs: one estimates an unknown KK from oracle-mediated structure in Rd\mathbb{R}^d, and the other imposes a desired kk on generative attention dynamics.

2. Oracle-based CountCluster: problem formulation

In the clustering setting, one is given a finite set XRdX\subset\mathbb{R}^d of kk0 points and an unknown ground-truth partition kk1, with kk2 itself unknown (Li et al., 2021). For each true cluster kk3, the centroid is

kk4

The available supervision is an oracle for same-cluster queries,

kk5

which returns "Yes" if kk6 and kk7 lie in the same kk8, and "No" otherwise.

The theoretical stopping condition is defined through a reducibility notion. Let kk9 be any subset of recovered cluster-indices and let kk0 be their approximate centroids. The squared-kk1 coverage cost is

kk2

The true clustering is said to be kk3-reducible with respect to kk4 if for every kk5,

kk6

The stated intuition is that if the remaining clusters can already be covered by the recovered ones at tolerable extra cost, recovery may stop (Li et al., 2021).

This formulation is structurally different from methods that infer kk7 from objective-function elbows or eigengaps. CountCluster does not begin with a fixed candidate kk8, and it does not define success as optimizing a global partition objective over all points. Instead, it incrementally discovers clusters through adaptive sampling and oracle queries until no new cluster label is found.

3. Algorithmic structure of Basic CountCluster and Improved CountCluster

The first algorithm, Basic CountCluster, runs in rounds kk9, maintaining the set KK0 of recovered cluster-indices and an approximate centroid KK1 for each KK2, with

KK3

Each round has four phases (Li et al., 2021).

In Phase 1, Discover, the algorithm draws

KK4

points by KK5-sampling with respect to KK6, classifies each new sample via same-cluster queries, and terminates if no new cluster appears. Otherwise the set KK7 contains the newly discovered labels. In Phase 2, Identify largest, it continues KK8-sampling until for each KK9 it has seen at least

Pq(y)P_q(y)0

samples in cluster Pq(y)P_q(y)1, then selects Pq(y)P_q(y)2 with the largest empirical sample count. In Phase 3, Pivot selection, it continues sampling until it sees

Pq(y)P_q(y)3

total points and chooses a pivot Pq(y)P_q(y)4 among samples labeled Pq(y)P_q(y)5 minimizing Pq(y)P_q(y)6. In Phase 4, Rejection sampling + centroid, when a sampled point Pq(y)P_q(y)7 is classified into Pq(y)P_q(y)8, it is accepted with probability

Pq(y)P_q(y)9

After collecting

D2D^20

such points for cluster D2D^21, the algorithm sets D2D^22 to their empirical mean and adds D2D^23 to D2D^24 (Li et al., 2021).

Improved CountCluster preserves the same high-level loop but recovers a whole batch of new clusters D2D^25 instead of a single D2D^26 (Li et al., 2021). After collecting a moderate number of D2D^27 samples, it computes empirical frequencies D2D^28 for each discovered D2D^29, partitions KK0 into logarithmic bands by

KK1

and declares a band heavy if the sum of frequencies in the band is at least KK2. All clusters in heavy bands form KK3; pivots KK4 are selected for every KK5, rejection sampling is performed simultaneously, and KK6 is batch-added to KK7. To cope with unknown true KK8, the algorithm outer-loops over guesses KK9, accepting rounds while Rd\mathbb{R}^d0 and stopping when no new clusters appear and Rd\mathbb{R}^d1.

Both algorithms return

Rd\mathbb{R}^d2

They therefore treat cluster counting as a byproduct of certified cluster recovery rather than as a standalone model-selection score.

4. Theoretical guarantees and practical behavior of oracle-based CountCluster

The Basic algorithm has the following guarantee: with probability at least Rd\mathbb{R}^d3, upon termination it returns a set Rd\mathbb{R}^d4 satisfying Rd\mathbb{R}^d5-reducibility, and for each Rd\mathbb{R}^d6,

Rd\mathbb{R}^d7

Its oracle-query complexity is

Rd\mathbb{R}^d8

where Rd\mathbb{R}^d9 is the number of recovered clusters and kk0 the total number of discovered but not necessarily recovered clusters (Li et al., 2021).

The Improved algorithm has the same success probability and approximate-centroid guarantees, with query complexity

kk1

The stated source of the kk2 factor is the outer loop over guesses kk3, and the paper notes that this factor can be removed at the cost of more careful bookkeeping (Li et al., 2021). Concentration is controlled phasewise by additive and multiplicative Chernoff bounds, with insufficient new-cluster mass bounded by

kk4

and bad center approximation bounded by

kk5

A union bound over rounds yields total failure at most kk6.

The count estimate is exact under the appropriate structural condition. Both algorithms terminate precisely when no new cluster label is discovered in Phase 1, and under the kk7-reducibility assumption the true number of clusters kk8 satisfies kk9. More generally, the algorithms recover all clusters whose coverage costs exceed the XRdX\subset\mathbb{R}^d0-threshold; the remaining clusters are covered by the recovered ones. Thus XRdX\subset\mathbb{R}^d1 is zero when the entire true set is XRdX\subset\mathbb{R}^d2-irreducible (Li et al., 2021).

Experiments on synthetic data with million-point, power-law cluster sizes and varying collision parameter XRdX\subset\mathbb{R}^d3, and on real data including Shuttle and KDD99, show that the basic and improved algorithms recover more clusters under the same query budget than uniform sampling; approximate-centroid error is below XRdX\subset\mathbb{R}^d4 in all settings; the batch version runs in fewer rounds and less wall-clock time; and a nearest-approximate-center heuristic classifies new points correctly with just one extra query in approximately XRdX\subset\mathbb{R}^d5–XRdX\subset\mathbb{R}^d6 of cases (Li et al., 2021). A plausible implication is that CountCluster is designed for query efficiency under weak structural assumptions rather than for unsupervised operation without interaction.

5. CountCluster for text-to-image generation: attention-space formulation

In diffusion-based text-to-image generation, CountCluster is a training-free object quantity guidance method based on clustering object cross-attention maps at inference time (Lee et al., 14 Aug 2025). The latent at timestep XRdX\subset\mathbb{R}^d7 is denoted XRdX\subset\mathbb{R}^d8. The prompt contains an object token XRdX\subset\mathbb{R}^d9 with desired count kk00. At each timestep kk01, the cross-attention layer for token kk02 produces a two-dimensional attention map

kk03

where kk04 is the attention weight on spatial patch kk05 for token kk06.

The method extracts kk07 from one or more early layers of the U-Net, with examples given as layers at kk08, and applies Gaussian smoothing with kernel size kk09 and kk10, min-max normalization to kk11, and thresholding at kk12, for example kk13, to discard low-attention patches (Lee et al., 14 Aug 2025). The set of early timesteps where clustering is applied is

kk14

with the example kk15.

The goal is to partition the set of candidate patch coordinates

kk16

into exactly kk17 clusters, so that each cluster corresponds to one object. Cluster centers kk18 are selected by a greedy max-min procedure: patches are sorted by descending attention score, and a patch is accepted as a center if its Euclidean distance to all previously chosen centers is at least

kk19

The assignments are then defined by nearest center,

kk20

The stated role of kk21 is to enforce roughly one object per kk22 distance (Lee et al., 14 Aug 2025).

This formulation operationalizes the claim that the number of object instances in the generated image is largely determined in the early timesteps of the denoising process, and that the highly activated regions in the object cross-attention map at those timesteps should match the input object quantity while remaining clearly separated (Lee et al., 14 Aug 2025).

6. Target distribution, clustering loss, and inference-time latent refinement

For each cluster kk23, CountCluster defines an ideal distribution in which attention forms a single blob decaying from center kk24 to a boundary where the ideal attention equals kk25 (Lee et al., 14 Aug 2025). With kk26 and radius kk27 given by the distance from kk28 to the farthest assigned patch, or simply kk29, the standard deviation is

kk30

The target Gaussian is

kk31

The normalized actual attention on patches assigned to cluster kk32 is

kk33

Similarity is measured by

kk34

The clustering loss is the sum of these divergences normalized by kk35: kk36 The stated reason for the kk37 normalization is that when kk38 increases, each cluster’s area shrinks and its individual KL tends to drop, whereas dividing by kk39 keeps the loss scale roughly independent of kk40 and allows the overall penalty to rise if clustering fails (Lee et al., 14 Aug 2025).

Inference interleaves standard diffusion denoising with gradient steps on the latent kk41. At each kk42, the gradient

kk43

is computed and the latent is updated as

kk44

Example step sizes are kk45 for SDXL and kk46 for SD2.1, and refinement stops when kk47 drops below thresholds such as kk48 at kk49 and kk50 at kk51 (Lee et al., 14 Aug 2025).

The full inference algorithm begins by tokenizing the prompt, running the text encoder, and initializing kk52. For each timestep kk53, the method computes the standard DDIM or ancestral update, and if kk54, it extracts and normalizes kk55, smooths and thresholds it at kk56, selects centers, assigns patches, constructs Gaussian targets, forms kk57, and performs the gradient step. The final latent kk58 is then decoded to an image (Lee et al., 14 Aug 2025).

A common misconception would be to treat this CountCluster as a conventional clustering algorithm for unlabeled datasets. The paper’s formulation is narrower: it is an inference-time control method for quantity alignment in diffusion models, and its "clusters" are clusters of attention patches rather than clusters of input data points.

7. Empirical results, limitations, and relation to other count-estimation methods

For text-to-image generation, the reported models are Stable Diffusion 2.1 and SDXL. The prompt set is “A photo of [count] [object]” with kk59 and kk60 object categories, yielding kk61 prompt variants and kk62 images over kk63 seeds (Lee et al., 14 Aug 2025). Clustering hyperparameters are kk64, kk65, and kk66, with refinement thresholds kk67. Accuracy, MAE, and RMSE are evaluated using predictions by CountGD and TIFA.

On SD2.1, the reported values are kk68 accuracy, kk69 MAE, and kk70 RMSE for the baseline SD2.1; kk71, kk72, and kk73 for Counting Guidance; and kk74, kk75, and kk76 for CountCluster. On SDXL, the values are kk77, kk78, and kk79 for SDXL; kk80, kk81, and kk82 for Zafar et al.; kk83, kk84, and kk85 for CountGen; and kk86, kk87, and kk88 for CountCluster (Lee et al., 14 Aug 2025). The paper states that Ours(SDXL) beats CountGen by kk89p in accuracy and by kk90p over plain SDXL, and that TIFA VQA scores improve by kk91p versus baselines. Ablation on SDXL reports kk92 accuracy without the min-distance constraint and kk93 accuracy without kk94 scaling (Lee et al., 14 Aug 2025).

Inference cost is also reported: on SDXL, kk95 s and kk96 GB for SDXL, kk97 s and kk98 GB for CountGen, and kk99 s and kk00 GB for CountCluster, with CountGen using kk01 GPU and the others using a single kk02 (Lee et al., 14 Aug 2025). This suggests that the method targets a trade-off between count accuracy and inference overhead while remaining training-free and external-tool-free.

For the oracle-based clustering CountCluster, the main limitations arise from its assumptions and oracle dependence. Its guarantees are conditional on kk03-reducibility, and its operation requires access to same-cluster queries (Li et al., 2021). For the diffusion CountCluster, the method presumes access to internal cross-attention maps at selected early timesteps and depends on hyperparameters such as kk04, kk05, timestep selection, and latent step sizes (Lee et al., 14 Aug 2025). In that sense, the two CountCluster methods occupy distinct methodological niches. One is an active learning algorithm with provable query complexity and stopping guarantees; the other is an inference-time control mechanism that shapes attention geometry to enforce an externally specified quantity.

Relative to broader count-estimation approaches, these methods illustrate two general paradigms. Classical cluster-number estimation via entropy and purity stabilization, consensus spectral gaps, or quantum interference derives kk06 from structural signatures in data representations [(Grace et al., 2015); (Race et al., 2014); (Muthyala et al., 2020)]. CountCluster in the oracle setting instead discovers kk07 through adaptive querying (Li et al., 2021). CountCluster in text-to-image generation does not estimate a latent unknown kk08; it conditions generation on a known target count and uses clustering as a control primitive (Lee et al., 14 Aug 2025). The commonality is therefore conceptual rather than algorithmic: in both cases, clustering is used as the mechanism by which multiplicity becomes explicit.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to CountCluster.