Unified Visual Understanding: Turning Tasks into Reversible Image Generation
This article explains a technical approach that unifies multiple visual understanding tasks through a single generative model. It covers the motivation for unified modeling, how task outputs are encoded into reversible RGB images for depth estimation, surface normals, semantic segmentation, instance segmentation, and referring expression segmentation, the lightweight instruction-tuning strategy, observed results and limitations, and practical engineering recommendations. Readers will learn how a shared encoding-decoding protocol enables one model to handle both generation and understanding.
1. Why Visual Tasks Need Unified Modeling
Traditional vision systems are usually assembled from multiple specialized models: depth estimation, surface normal estimation, semantic segmentation, instance segmentation, and referring expression segmentation each have their own network architecture, output definition, and post-processing pipeline. This creates three types of engineering cost:
- Too many models make the training, evaluation, and deployment pipeline complex.
- Tasks lack a shared representation, so the same visual priors cannot be reused.
- Heterogeneous interfaces force the business side to write separate calling and parsing logic for each task.
Generative pre-trained models have learned strong visual priors and instruction-following ability from large-scale image-text data. A natural question follows: can “understanding” also be written as “generation,” so that a single model completes multiple tasks through one interface? The technical route discussed here is a representative practice of this idea: applying lightweight instruction tuning to a pre-trained image generation model, parameterizing the output of visual tasks as RGB images, and covering both generation and understanding with one model.
2. Core Idea: Encoding Understanding Output as Reversible Images
The key to this method is reversible encoding. The model takes an input image and a text instruction, and outputs an RGB image. This image is not a visualization meant for human viewing; instead, following the scheme specified by the instruction, it encodes the task result into pixel colors. During inference, the same rules are used to decode the image and recover the values or labels the task requires.
Reversibility ensures no information is lost and makes a unified interface possible: regardless of how different the tasks are, the model output is always an RGB image, and the differences appear only in the encoding protocol specified by the prompt and in the decoder implementation.
2.1 Depth Estimation: From Metric Depth to Pseudo-Color
Depth values are unbounded, so the unbounded range must first be compressed into a bounded interval and then mapped to the color space. A common approach is:
d ∈ [0, ∞)-> power transform -> t ∈ [0, 1)-> piecewise linear interpolation along the edges of the color cube-> RGB pseudo-color
The color path passes through endpoints such as black, blue, cyan, green, yellow, red, magenta, and white in sequence. During decoding, the pixel color is projected back onto the edge of the cube to obtain t, and an inverse transform recovers the metric depth. Because both the transform and the interpolation are strictly monotonic and one-to-one, the whole process is reversible.
2.2 Surface Normals: Naturally Aligned with RGB
All three components of a normal vector fall in [-1, 1], which differs from the RGB range [0, 1] by only one linear transform:
R = (x + 1) / 2G = (y + 1) / 2B = (z + 1) / 2
Decoding applies the inverse linear mapping and then normalizes the vector. This encoding introduces almost no additional error, making it the simplest of the three tasks.
2.3 Semantic Segmentation: Class Coloring Driven by a Color Table
The prompt provides a structured mapping from classes to colors, for example:
{"road": "#808080", "car": "#FF0000"}
The model outputs an image with each pixel colored by its class; during decoding, pixels are matched back to classes by color distance. In practice, issues such as color table conflicts and boundary color blending caused by anti-aliasing need attention, and are usually mitigated by limiting the palette and applying nearest-neighbor matching in boundary regions.
2.4 Instance Segmentation and Referring Expression Segmentation
Instance segmentation processes one class at a time, with the model automatically assigning different colors to different instances, and the decoding stage distinguishes instances through color clustering. Referring expression segmentation takes a natural language referring expression as part of the prompt and outputs the colored result for the target region. Both reuse the same “color as label” decoding framework.
3. Training Strategy: Low-Ratio Mixing and Lightweight Tuning
The training stage does not train an understanding module from scratch. Instead, visual task data is mixed into the original image generation training data at a relatively low ratio for lightweight instruction tuning. The logic is that visual understanding ability has already formed during generative pre-training, and tuning only needs to teach the model to “output an RGB image in the format required by the prompt.”
Low-ratio mixing also helps suppress catastrophic forgetting, so the original generation and editing capabilities are largely preserved. In practice, three points are worth attention: encoding consistency of the task data, diversity of prompt templates, and a ratio sweep between generation data and understanding data.
4. Results and Boundaries
Based on public descriptions, this route achieves usable results on 2D and 3D understanding tasks while generation ability stays roughly on par: it wins about 53.5% against the original model on a general generation evaluation and about 47.8% on an image editing benchmark, which is the same performance range.
Its boundaries should be viewed objectively: reversible encoding depends on color precision, so compression and interpolation introduce quantization error; the number of colors is limited by the available palette, and decoding becomes harder when there are too many classes or instances; the prompt protocol needs strict constraints, otherwise the decoding failure rate rises.
5. Engineering Recommendations
To borrow this idea in your own system, focus on the following: first define a clear encoding protocol and unit tests for the decoder; validate reversibility with synthetic data; put prompt templates under version control; and run inference services on a container platform in the cloud, with object storage for data, and logging and monitoring services to track decoding failure rate and latency. General-purpose cloud product categories from Baidu AI Cloud can serve as optional infrastructure for hosting such a unified inference service.
