Skip to content

naver-ai/Visual-Style-Prompting

Repository files navigation

🎨 Visual Style Prompting with Swapping Self-Attention

: Text-to-Stylized image with Training-free

ArXiv | 📖 Paper | ✨ Project page

Authors    Jaeseok Jeong1,2*, Junho Kim1*, Yunjey Choi1, Gayoung Lee1, Youngjung Uh2†
         1NAVER AI Lab, 2Yonsei University
         *Equal Contribution, Corresponding author

teaser

🔆 Abstract

In the evolving domain of text-to-image generation, diffusion models have emerged as powerful tools in content creation. Despite their remarkable capability, existing models still face challenges in achieving controlled generation with a consistent style, requiring costly fine-tuning or often inadequately transferring the visual elements due to content leakage. To address these challenges, we propose a novel approach, visual style prompting, to produce a diverse range of images while maintaining specific style elements and nuances. During the denoising process, we keep the query from original features while swapping the key and value with those from reference features in the late self-attention layers. This approach allows for the visual style prompting without any fine-tuning, ensuring that generated images maintain a faithful style. Through extensive evaluation across various styles and text prompts, our method demonstrates superiority over existing approaches, best reflecting the style of the references and ensuring that resulting images match the text prompts most accurately.


🔥 To do

  • color calibration to use a real image as reference
  • user image in demo
  • gpu upgrade in demo (Thanks for HF)

🤗 HuggingFace Demo


✨ Requirements

> pytorch 1.13.1
> pip install --upgrade diffusers accelerate transformers einops kornia gradio triton xformers==0.0.16

✨ Usage

w/ Predefined styles in config file

> python vsp_script.py --style fire

vsp_img

👉 w/ Controlnet

> python vsp_control-edge_script.py --style fire --controlnet_scale 0.5 --canny_img_path assets/edge_dir
> python vsp_control-depth_script.py --style fire --controlnet_scale 0.5 --depth_img_path assets/depth_dir

control_img

👉 w/ User image

> python vsp_real_script.py --img_path assets/real_dir --tar_obj cat --output_num 5 --color_cal_start_t 150 --color_cal_window_size 50
  • For better results, you can add more style description only to inference image by directly editing code.
    • vsp_real_script.py -> def create_prompt
    • Save your images in the style_name.png format.
      • e.g.,) The starry night.png real_img

✨ Misc

👉 How to visualize the attention map ?

  1. Save the attention map.
> python visualize_attention_src/save_attn_map_script.py
  1. Visualize the attention map.
> python visualize_attention_src/visualize_attn_map_script.py

📚 Citation

@article{jeong2024visual,
  title={Visual Style Prompting with Swapping Self-Attention},
  author={Jeong, Jaeseok and Kim, Junho and Choi, Yunjey and Lee, Gayoung and Uh, Youngjung},
  journal={arXiv preprint arXiv:2402.12974},
  year={2024}
}

✨ License

Visual Style Prompting with Swapping Self-Attention
Copyright (c) 2024-present NAVER Cloud Corp.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.