PHOTOSWAP: Personalized Subject Swapping in Images

Jing Gu, Yilin Wang, Nanxuan Zhao, Tsu-Jui Fu, Wei Xiong, Qing Liu, Zhifei Zhang, He Zhang, Jianming Zhang, HyunJoon Jung, Xin Eric Wang

Abstract

Photoswap is a novel training-free framework designed for personalized subject swapping in images. While text-to-image diffusion models have revolutionized image generation, precise editing—specifically replacing a generic subject with a personalized one while maintaining scene integrity—remains challenging. Photoswap addresses this by manipulating the self-attention and cross-attention layers of pre-trained models. This approach preserves the original image's pose, geometry, and background while seamlessly integrating a new identity, significantly outperforming existing image-editing baselines.

Introduction

The rise of text-to-image (T2I) models like Stable Diffusion has simplified image creation, yet high-precision editing remains a significant hurdle. A particularly difficult task is personalized subject swapping: the ability to replace a generic subject in a photograph (e.g., a random cat) with a specific, user-defined subject (e.g., a specific pet) without altering the surrounding environment.

Existing methods often face an "identity vs. layout" trade-off. Modifying text prompts typically causes the entire composition, lighting, and background to shift. Conversely, masking techniques often fail to capture the original subject's exact pose or ensure natural interaction with the background. Photoswap bridges this gap by "locking" the spatial layout while "injecting" a new personalized identity.

Methodology

The Photoswap pipeline operates in three distinct stages:

  1. Visual Concept Learning: The model first learns the target subject's appearance. Using DreamBooth, a diffusion model is fine-tuned on 3–5 reference images of the subject, associating it with a unique identifier (e.g., *).
  2. Image Inversion: To edit a source image, the model must reconstruct it. DDIM inversion and null-text optimization are employed to extract the initial noise and internal attention maps responsible for the source image's structure.
  3. Training-Free Attention Swapping: This core innovation involves swapping three components from the source image's generation process into the new generation:
  4. Self-attention maps ($M$): Govern spatial layout and geometry.
  5. Cross-attention maps ($A$): Align text prompts with image structure.
  6. Self-attention output ($\phi$): Encapsulates rich content and contextual information.
Figure 1: Photoswap demonstrates the ability to swap diverse subjects—including cartoons, objects, and celebrities—while maintaining the source image's composition.

By injecting these variables during the early denoising steps, the model follows the "skeleton" of the original image while rendering the "skin" of the new personalized subject.

Key Insights

  • Self-Attention Output ($\phi$) for Layout Control: Swapping the output of the self-attention layer proved more effective for layout preservation than swapping attention maps alone. This provides holistic control over gestures and background details.
  • Temporal Control: Layout is established during the initial denoising steps. By limiting the swapping mechanism to these early steps (controlled by the $\lambda$ hyperparameter), the model retains the flexibility to refine textures and identity in later stages.
  • Training-Free Flexibility: The swapping mechanism is "plug-and-play" once the subject's identity is learned, requiring no per-image optimization.

Key Results

Photoswap was evaluated against a state-of-the-art baseline combining Prompt-to-Prompt (P2P) and DreamBooth.

Figure 2: Qualitative comparison showing Photoswap results for human and animal subjects. The method effectively preserves the source layout while adopting the reference identity.
  • Human Preference: In a blind user study on Amazon Mechanical Turk (99 examples), Photoswap was preferred for overall quality 50.8% of the time, compared to 28.0% for the baseline.
  • Identity and Background Preservation: Photoswap significantly outperformed the baseline in subject identity preservation (46.8% vs. 25.6%) and background consistency (40.7% vs. 32.7%).
  • Robustness: The framework handles challenging scenarios, such as multi-subject images and occlusions (e.g., a dog in a suit), with high fidelity.

Limitations and Ethical Considerations

Despite its success, Photoswap inherits some limitations from its base model, Stable Diffusion, such as occasional inaccuracies in rendering fine details like fingers. Intricate, abstract backgrounds (e.g., complex formulas) may also lose detail during inversion.

Ethically, the authors note the potential for misuse in creating deepfakes. They recommend using the tool for subjects of similar racial backgrounds to maintain authenticity and avoid unintended homogenization of skin tones. Future work will focus on improving detail accuracy and integrating the framework into professional editing workflows.

Summary updated

BibTeX
@inproceedings{gu2023photoswap,
  author = {Jing Gu and Yilin Wang and Nanxuan Zhao and Tsu-Jui Fu and Wei Xiong and Qing Liu and Zhifei Zhang and HE Zhang and Jianming Zhang and HyunJoon Jung and Xin Eric Wang},
  title = {{PHOTOSWAP: Personalized Subject Swapping in Images}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=qqcIM8NiiB},
}
Figure