MAGIC: Mask-Guided Image Synthesis by Inverting a Quasi-Robust Classifier

Mozhdeh Rouhsedaghat, Masoud Monajatipoor, C. -c. Jay Kuo, Iacopo Masi

TL;DR

MAGIC is a novel one-shot, mask-guided image synthesis framework that allows users to precisely manipulate an image's layout and geometry using simple binary masks. By inverting a "quasi-robust" classifier alongside a patch-based encoder-decoder, it achieves high-fidelity shape and location control from a single reference image without requiring massive training datasets.

What Problem Does This Paper Address?

Image synthesis typically requires large, well-annotated datasets to learn complex data distributions. "One-shot" image synthesis attempts to bypass this by generating variations from just a single training image. However, existing methods struggle with structural control:

  • Texture-based models (like SinGAN) excel at repetitive textures (e.g., landscapes) but fail on distinct, non-repetitive objects.
  • Classifier inversion models (like IMAGINE) preserve high-level semantics but lack precise spatial control, often requiring detailed, color-matched user paintings to guide shape changes.
  • Mask-guided models (like DEEPSIM) require highly detailed edge or multi-class segmentation maps and rely on aggressive data augmentation, which frequently introduces unnatural, wavy artifacts.

MAGIC addresses these gaps by enabling diverse manipulations—such as position control, non-rigid shape deformation, and object copying/moving—using only a single image and a loose, binary guide mask.

Multiple image manipulation tasks with a single method (MAGIC).

Methods

The core architecture of MAGIC relies on three main components optimized simultaneously through backpropagation:

  1. Quasi-Robust Classifier Inversion: Standard classifiers yield noisy, chaotic gradients during inversion. Conversely, strongly robust classifiers (trained to withstand large adversarial attacks) produce gradients that capture only coarse shapes, losing fine details. MAGIC introduces a quasi-robust classifier trained with a very small adversarial perturbation ($\ell_2$ norm, $\epsilon = 0.05$). This "sweet spot" provides clean, perceptually aligned gradients that trace sharp object boundaries while maintaining high classification accuracy.
  2. Mask-Guided Encoder-Decoder (ED) Inversion: Instead of mapping masks to images, MAGIC trains a patch-based ED offline to do the reverse: map the input image to its binary mask. During synthesis, the network weights are frozen, and the user's target mask replaces the original mask. Backpropagating the cross-entropy loss forces the synthesized image to conform to the new target shape.
  3. Large Receptive Field PatchGAN: To ensure texture consistency and prevent the object from fragmenting, MAGIC incorporates a PatchGAN discriminator with a $21 \times 21$ receptive field (significantly larger than the $9 \times 9$ field used in prior work).
Overview of MAGIC framework and gradient comparison.

Datasets

  • ImageNet: Used to pre-train the quasi-robust ResNet-50 classifier. Evaluation images were also sampled from the ImageNet validation set.
  • Web Images: Used to test the model's generalization capabilities on diverse, real-world scenes and objects.

Key Insights and Ideas

  • The Quasi-Robust Sweet Spot: The authors discovered a crucial trade-off in adversarial robustness for image synthesis. As shown in the gradient visualizations, a standard model is too noisy, while a strongly robust model ($\epsilon = 5.0$) ignores fine edges. A tiny perturbation ($\epsilon = 0.05$) yields the perfect balance for generating sharp, realistic details.
Visualization of the gradient of the loss with respect to the input across different epsilon values.
  • Inverting the Segmentation Network: Rather than using a generative network to turn a mask into an image (which biases the model toward the training augmentations), inverting a frozen image-to-mask network acts as a strong spatial prior that naturally guides deformations.

Key Results

MAGIC was evaluated against state-of-the-art models like DEEPSIM and IMAGINE using both automated metrics and human perception:

  • Quantitative Performance: MAGIC significantly outperformed DEEPSIM on both object and scene synthesis using Fréchet Inception Distance (FID) and Single Image FID (SIFID):
  • Objects FID: 30.79 (MAGIC) vs. 72.71 (DEEPSIM)
  • Scenes FID: 41.36 (MAGIC) vs. 136.87 (DEEPSIM)
  • Human Evaluation: In a user study with 120 participants, MAGIC was preferred over DEEPSIM by a margin of 55.42% to 44.58% for objects, and an overwhelming 86.81% to 13.19% for complex scenes.
  • Efficiency: MAGIC achieves these results with only 26.25M parameters, making it vastly lighter than DEEPSIM (183M parameters).
Synthesized images demonstrating how different levels of adversarial robustness affect output fragmentation and blurriness.

Limitations and Future Work

Despite its strengths, MAGIC has a few notable limitations:

  • Object Removal & Scale Changes: Because the model enforces a feature-matching regularizer to preserve the original image's statistics, it cannot completely remove objects or handle extreme scale changes.
  • Artifacts: The system occasionally suffers from "ghost effects" or retains faint, pale traces of the original object's details in its old position.

For future work, the authors plan to theoretically investigate the link between quasi-robust classifiers and score-matching generative models, as well as extend MAGIC to image inpainting tasks.

Summary updated

BibTeX
@inproceedings{rouhsedaghat2023magic,
  author = {Mozhdeh Rouhsedaghat and Masoud Monajatipoor and C. -C. Jay Kuo and Iacopo Masi},
  title = {{MAGIC: Mask-Guided Image Synthesis by Inverting a Quasi-Robust Classifier}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2023},
  doi = {10.1609/aaai.v37i2.25311},
}
Figure