Abstract
Text-to-image diffusion models generate realistic and coherent images but often fail to follow numerical instructions in text, revealing a gap between language and visual representation. Interestingly, we found that these models are not entirely blind to numbers—they are implicitly aware of their own counting accuracy, as their internal signals shift in consistent ways depending on whether the output meets the specified count. This observation suggests that the model already encodes a latent notion of numerical correctness, which can be harnessed to guide generation more precisely. Building on this intuition, we introduce CountSteer, a training-free method that improves generation of specified object counts by steering the model's cross-attention hidden states during inference. In our experiments, CountSteer improved object-count accuracy by about 4% without compromising visual quality, demonstrating a simple yet effective step toward more controllable and semantically reliable text-to-image generation.
Introduction
While modern diffusion models like Stable Diffusion can generate breathtaking art, they are notoriously limited in their ability to adhere to precise numerical constraints. A request for "three apples" frequently results in a varying number of objects or indistinct clusters. This "numerical fidelity" gap stems from a disconnect between linguistic numerical concepts and their visual representation within the model's latent space.
Existing solutions often rely on computationally expensive fine-tuning or architectural modifications. CountSteer addresses this problem by investigating whether the model possesses an inherent, latent understanding of counting that can be leveraged during inference without additional training.
Methodology
The core discovery driving CountSteer is that internal cross-attention hidden states for "correct" generations (those matching the prompt count) and "incorrect" ones are linearly separable. This suggests that the model's internal state already contains a signal for numerical accuracy.
CountSteer operates through a three-step inference-time process:
- Identifying the Steering Direction: A "base steering vector" is calculated by finding the difference between the mean hidden states of correct and incorrect samples from a calibration set.
- Adaptive Steering: To avoid image distortion from "over-steering," CountSteer employs an adaptive scaling factor. This factor dynamically adjusts the nudge based on how far the current generation's state is from the target "correct" distribution.
- Early Intervention: The authors apply this steering only during the first 10 steps of the 50-step denoising process. This strategy targets the early phase where global layout and object counts are established, leaving later steps to refine fine-grained visual details.
Experimental Setup
To evaluate the method, the researchers utilized a custom dataset of 600 prompts following the template "{count} {object}" (e.g., "four skateboards"), generated via GPT-4o. The study focused on counts from one to four, as the base model (Stable Diffusion v1.5) exhibits significant performance degradation beyond this range. Evaluation was conducted using LLaVA-OneVision to objectively count objects in the generated outputs.
Results and Discussion
Experimental results demonstrate that CountSteer effectively bridges the numerical fidelity gap. Compared to the Stable Diffusion v1.5 baseline, CountSteer improved object-count accuracy from 50.0% to 54.0%. Furthermore, the Mean Absolute Error (MAE) decreased from 1.125 to 0.940, indicating that even when the model failed to reach the exact count, its errors were less severe.
Crucially, this improvement did not come at the cost of image quality. The CLIP-Score remained stable (~30.39 for CountSteer vs. 30.99 for the baseline), confirming that the steering process preserves the semantic relevance and visual fidelity of the generated images.
Conclusion and Future Work
CountSteer proves that diffusion models possess an implicit numerical awareness that can be harnessed through simple geometric steering in the attention space. While the method currently faces a "wall" at counts higher than four and can occasionally lead to feature duplication (overgeneration), it provides a powerful, training-free framework for enhancing model controllability. Future research may extend this steering approach to other attributes such as spatial arrangement, color, or more complex multi-object interactions.
Summary updated