Abstract
Visual In-Context Learning (V-ICL) has emerged as a powerful paradigm for solving vision tasks by providing a few demonstrations at inference time. However, existing generalist models often struggle with Optical Character Recognition (OCR) tasks due to visual heterogeneity and shallow reasoning. We present ConText, the first framework to successfully adapt V-ICL specifically for text removal and segmentation. By employing a novel task-chaining mechanism and context-aware aggregation, ConText achieves state-of-the-art performance across multiple benchmarks without task-specific fine-tuning.
Introduction
Visual In-Context Learning allows models to generalize to new tasks using prompts, similar to Large Language Models. Despite the success of generalists like Painter and SegGPT, OCR tasks remain challenging. These models often fail due to three primary factors: a reliance on single-step reasoning-as-reconstruction, context-free fusion of demonstrations, and the extreme visual heterogeneity of text styles. ConText addresses these hurdles by moving beyond simple pattern matching toward a more structured, context-sensitive reasoning process.
Methodology
ConText introduces three core innovations to enhance the in-context learnability of OCR tasks:
Task-Chaining
Instead of a direct mapping from image to label, ConText utilizes a chain of related tasks: Image $\rightarrow$ Text Removal $\rightarrow$ Text Segmentation. This provides the model with enriched intermediate representations, effectively creating a visual "chain of thought." By solving removal and segmentation simultaneously, the model develops a deeper understanding of text structures.
Context-Aware Aggregation (CAA)
To ensure the model actively utilizes the provided demonstrations, we introduce the CAA module. This cross-attention-based component explicitly integrates patterns from the demonstration pairs into the query's latent representation, preventing the model from ignoring the context and falling into a "specialist" trap.
Self-Prompting Strategy
To combat visual heterogeneity, ConText employs a self-prompting strategy during training. The model is occasionally tasked with using fragments of the query image itself as the demonstration. This forces the model to maintain sensitivity to the provided context even when styles are highly diverse.
Experimental Setup and Datasets
ConText was evaluated on a comprehensive suite of benchmarks, including HierText, TotalText, and ICDAR13 FST for segmentation, and SCUT-EnsText and SCUT-Syn for text removal. Additionally, the authors introduced PromptText, a new benchmark designed to test the model's ability to follow human-oriented visual instructions, such as segmenting or erasing areas marked by specific visual indicators (e.g., red circles).
Results and Analysis
ConText achieved new state-of-the-art (SOTA) results across all evaluated benchmarks. In text removal, it improved performance by +4.50 PSNR over previous generalist baselines. In segmentation, it achieved a +3.34% fgIoU improvement.
Qualitative analysis demonstrates that ConText significantly outperforms existing generalists like SegGPT in accurately identifying and removing text while preserving background textures. Furthermore, its performance on the unseen FST dataset proves robust out-of-domain generalization, even surpassing some task-specific specialists.
Conclusion
ConText demonstrates that V-ICL can be effectively adapted for complex OCR tasks through structured task-chaining and improved context integration. While challenges remain regarding the diminishing returns of multi-shot prompting and the gap between synthetic and real-world data, ConText represents a significant step toward generalized visual reasoning in the OCR domain.
Summary updated