Images Speak in Images: A Generalist Painter for In-Context Visual Learning

Xinlong Wang, Wen Wang, Yue Cao, Chunhua Shen, Tiejun Huang

Abstract

In-context learning has revolutionized natural language processing, allowing models to adapt to new tasks via simple prompting. However, achieving similar flexibility in computer vision has remained challenging due to the diverse output formats required for different tasks. We present Painter, a generalist vision model that unifies diverse vision tasks—from high-level semantic segmentation to low-level image enhancement—into a single image-to-image "inpainting" framework. By representing task outputs as standard RGB images and employing masked image modeling, Painter can perform a wide array of vision tasks using only a visual prompt at inference time, without requiring task-specific heads or fine-tuning.

Introduction

The quest for a "universal" vision model has long been hindered by the heterogeneity of computer vision tasks. While semantic segmentation produces category masks, depth estimation yields continuous distance values, and keypoint detection outputs spatial coordinates. Traditionally, these differences necessitated "task-specific heads"—customized neural layers tailored to each output format. This architectural fragmentation prevents the development of a truly generalist interface capable of in-context learning, a capability that has made large language models like GPT-3 so versatile.

Previous attempts to bridge this gap by converting vision tasks into language tokens often suffer from a loss of spatial precision and increased computational overhead. Painter addresses this by proposing that "images speak in images," treating every vision task as a pixel-level reconstruction problem.

The Painter Framework

The core innovation of Painter lies in its unified approach to task representation and learning.

Unified Output Space

To eliminate task-specific architectures, Painter reshapes every possible output into a standard 3-channel RGB image. For instance, continuous depth values are mapped to a 0-255 integer range, while semantic categories are encoded into specific RGB colors using a mathematical base system. This transformation allows the model to use a single, vanilla Vision Transformer (ViT) backbone for all tasks.

Masked Image Modeling and In-Context Learning

Painter is trained using a variation of Masked Image Modeling (MIM). During training, the model is presented with a "stitch" of two image pairs from the same task: (Input A, Output A) and (Input B, Output B). A portion of Output B is masked, and the model is tasked with reconstructing these missing pixels. This setup forces the model to learn the relationship between an input and its corresponding output by using the first pair as a contextual reference.

The Painter framework uses a task prompt (image pair) to guide the model in generating the output for a new input image across various vision tasks.

At inference time, this mechanism enables in-context learning. A user provides a "Task Prompt"—an example pair showing an image and its ground truth—alongside a new query image. The model then "paints" the output for the query image based on the logic inferred from the prompt. Additionally, the authors found that "tuning" the pixels of the prompt image while keeping model weights frozen could further boost performance, mirroring prompt engineering in LLMs.

Experimental Results

Painter was evaluated across a broad spectrum of vision benchmarks, including high-level tasks (ADE-20K, MS-COCO) and low-level tasks (NYUv2, SIDD, LoL).

Performance on Standard Benchmarks

Despite its generalist nature, Painter achieves performance competitive with, and sometimes exceeding, specialized state-of-the-art models. Notably, it established a new record on the NYUv2 depth estimation benchmark with a 0.288 RMSE. In keypoint detection on COCO, it achieved 72.1 AP, significantly outperforming previous generalist architectures like Pix2Seq v2.

Qualitative results of Painter across diverse tasks including semantic segmentation, depth estimation, instance segmentation, keypoint detection, and image restoration.

Out-of-Domain Generalization

A key strength of Painter is its ability to generalize to unseen tasks. When tested on the FSS-1000 benchmark for "open-vocabulary" segmentation (e.g., identifying objects like koalas or butterflies not seen during training), Painter outperformed concurrent visual prompting models by a significant margin, achieving 62.3 mIoU compared to 58.3 for MAE-VQGAN.

Discussion and Conclusion

Painter demonstrates that pixels are a powerful and natural interface for general-purpose vision. By treating tasks as image-to-image translations, the model preserves critical spatial relationships and avoids the complexity of task-specific heads.

However, limitations remain. The current model operates at a fixed 448x448 resolution, which can be a bottleneck for tasks like panoptic segmentation that typically benefit from higher-resolution inputs. Furthermore, Painter is currently purely visual and lacks the ability to integrate natural language instructions. Future work involving the scaling of model parameters and the incorporation of multi-modal signals could pave the way for even more capable and intuitive visual assistants.

Summary updated

BibTeX
@inproceedings{wang2022images,
  author = {Xinlong Wang and Wen Wang and Yue Cao and Chunhua Shen and Tiejun Huang},
  title = {{Images Speak in Images: A Generalist Painter for In-Context Visual Learning}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2022},
}
Figure