naver-ai / Visual-Style-Prompting

Official Pytorch implementation of "Visual Style Prompting with Swapping Self-Attention"
https://curryjung.github.io/VisualStylePrompt/
Apache License 2.0
408 stars 30 forks source link
diffusion stable-diffusion

🎨 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


πŸ€— 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

πŸ“š 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.