Introduction
While modern generative AI models can produce high-fidelity images from text prompts, providing fine-grained control over spatial layout and object geometry remains a significant challenge. Traditional "sketch-to-photo" methods often rely on supervised learning, which requires large datasets of paired sketches and photographs. These methods are limited by data scarcity and the inherent "domain gap" between sparse, abstract line drawings and dense, realistic images.
MaskSketch introduces a novel approach to this problem by enabling unpaired, structure-guided generation. By leveraging the internal mechanics of a pre-trained masked generative transformer, MaskSketch allows users to guide image synthesis with simple sketches without requiring any paired training data or model fine-tuning.
The Challenge of Sketch-to-Photo Synthesis
Existing supervised methods for sketch-guided generation face two primary hurdles:
- Data Scarcity: Collecting high-quality pairs of hand-drawn sketches and corresponding photos is expensive and difficult to scale.
- Domain Inconsistency: Sketches and photos occupy different feature spaces. Models trained exclusively on natural images often struggle to interpret the abstract, high-contrast lines of a sketch as meaningful structural cues.
MaskSketch bypasses these issues by treating the sketch as a structural guide during the inference process of a model already trained on natural images.
Methodology: Masked Generation with Structural Guidance
The foundation of MaskSketch is MaskGIT, a generative transformer that creates images by iteratively unmasking visual tokens. MaskSketch modifies this iterative process through two key innovations:
1. Structure Similarity via Domain-Invariant Attention
The researchers discovered that the intermediate self-attention maps of a transformer encode structural information—such as object shape and scene layout—in a way that is remarkably consistent across both sketches and photos. To exploit this, they define a "structural distance" using Jeffrey’s divergence. This metric compares the self-attention maps of the input sketch with the attention maps of the emerging image tokens during generation.
2. Structure-Guided Parallel Decoding
During the generation process, MaskSketch employs a dual-masking strategy. Rather than simply selecting the most likely tokens based on the model's confidence, it filters candidates based on two criteria:
- Realism: Model confidence in the token's likelihood.
- Fidelity: Structural similarity to the input sketch.
To further refine the output, the system utilizes CLIP-based Rejection Sampling. By generating multiple candidates and using CLIP to evaluate the balance between structural accuracy and photorealism, the model selects the highest-quality result.
Experimental Evaluation
The authors evaluated MaskSketch across several benchmarks, including ImageNet-Sketch (50,000 real sketches), Pseudosketches (edge maps from ImageNet), and OpenSketches, a new dataset of 200 hand-drawn and digital sketches designed to simulate realistic human input.
Key Results
MaskSketch significantly outperformed existing unsupervised baselines and remained competitive with supervised methods:
- Realism: On ImageNet-Sketch, MaskSketch achieved a Fréchet Inception Distance (FID) of 33.24, a substantial improvement over the MUNIT baseline (68.65).
- User Preference: In human evaluation studies, users preferred MaskSketch results over competing methods nearly 60% of the time.
- Diversity: Unlike GAN-based approaches that often suffer from mode collapse, MaskSketch can generate a diverse array of realistic photos from a single sketch by varying the random seed.
Key Insights and Discussion
- Attention as a Universal Language: The most significant finding is that self-attention maps are "domain-invariant." A transformer perceives the underlying structure of an object similarly whether it is presented as a line drawing or a photograph.
- Layer Sensitivity: The research identified that deeper layers (specifically layers 16-22) capture high-level spatial layouts, while early layers focus on pixel-level reconstruction. By targeting these deeper layers for guidance, MaskSketch allows for creative interpretation of the sketch rather than a literal, rigid trace.
- Zero-Shot Flexibility: Because the method utilizes the internal features of a pre-trained model, it requires no new training, making it highly adaptable to various sketching styles.
Limitations and Future Work
Despite its performance, MaskSketch is computationally intensive. The requirement for 500 iterations and multiple sampling trials results in a generation time of approximately 750 seconds for a batch of 8 images on a TPUv4. Additionally, the coarseness of self-attention maps can lead to difficulties with extremely fine details or highly complex, overlapping scenes. Future research may focus on optimizing sampling speeds or adapting these structural guidance techniques to large-scale diffusion models.
Summary updated