StyleTokenizer: Defining Image Style by a Single Instance for Controlling Diffusion Models
Wen Li Muyuan Fang Cheng Zou Biao Gong Ruobing Zheng Meng Wang Jingdong Chen Ming Yang




 



StyleTokenizer













[1]Equal contribution




W. Author et al.




Ant Group, Hangzhou, China 

{liwen8459,fangmuyuan}@gmail.com {wuyou.zc,gongbiao.gb,
zhengruobing.zrb,darren.wm,jingdongchen.cjd,m.yang}@antgroup.com

StyleTokenizer: Defining Image Style by a Single Instance for Controlling Diffusion Models
    
Wen LiMuyuan FangCheng Zou Biao Gong Ruobing Zheng 

Meng Wang Jingdong Chen Ming Yang

    

============================================================================================

§ ABSTRACT 

Despite the burst of innovative methods for controlling the diffusion process, effectively controlling image styles in text-to-image generation remains a challenging task. Many adapter-based methods impose image representation conditions on the denoising process to accomplish image control. However these conditions are not aligned with the word embedding space, leading to interference between image and text control conditions and the potential loss of semantic information from the text prompt. Addressing this issue involves two key challenges. Firstly, how to inject the style representation without compromising the effectiveness of text representation in control. Secondly, how to obtain the accurate style representation from a single reference image. To tackle these challenges, we introduce StyleTokenizer, a zero-shot style control image generation method that aligns style representation with text representation using a style tokenizer. This alignment effectively minimizes the impact on the effectiveness of text prompts. Furthermore, we collect a well-labeled style dataset named Style30k to train a style feature extractor capable of accurately representing style while excluding other content information. Experimental results demonstrate that our method fully grasps the style characteristics of the reference image, generating appealing images that are consistent with both the target image style and text prompt. The code and dataset are available at https://github.com/alipay/style-tokenizerhttps://github.com/alipay/style-tokenizer.

  
   




§ INTRODUCTION







The field of image generation has experienced remarkable growth since the advent of diffusion-based methods, including notable examples such as DALLE-1/2/3 <cit.>, Stable Diffusion <cit.>, and Midjourney <cit.>. These advancements have paved the way for a diverse range of content control techniques <cit.>, enabling precise manipulation of layout, lines, depth, and other conditions. This not only enhances the stability of diffusion models but also broadens their applicability.
Despite such progress, achieving effortless and effective control over the fine-grained styles of synthesized images remains a formidable challenge. This limitation restricts the practical applicability and convenience of diffusion methods in various applications.


Previous GAN-based methods <cit.> have achieved some level of style control, but the generated effects are difficult to compare with those of diffusion models.
Diffusion-based methods such as Textual Inversion <cit.>, LoRA <cit.>, and Dreambooth <cit.> utilize a small amount of data of the same type to fine-tune pre-trained
text-to-image models to better reflect new aspects in training images. These methods can generate images with similar styles as the training images. However, they are also prone to overfitting with the specific content (e.g., a particular person or object) present in the training images. This makes it challenging to decouple style and content, resulting in difficulties in achieving precise style control.


For precise style control, one intuitive approach is to employ adapter-based techniques like IP-adapter <cit.>, 
 StyleAdapter <cit.>, InstantStyle <cit.>, etc. These strategies embed style representation within the UNet architecture by introducing an extra cross-attention layer. Yet, as text and style representations span in distinct spaces, managing them via individual cross-attention processes may lead to discrepancies in the control signals.
As illustrated in Fig.<ref>, the adapter-based approaches apply text and style conditions simultaneously during the denoising process, which may cause interference between the controls and losing semantics.
Thus, the crucial challenge lies in introducing style representation while preserving the integrity of text representation for control purposes.

Leveraging the approach of tokenizing visual features for alignment with linguistic space, such as LLaVA <cit.>, we can improve the handling of intricate details in both images and text. Specifically, tokenizing style elements like text prompts significantly enhances the coordination and control within text prompts. This approach also effectively decouples style and content representations: after tokenization, the style from reference images and content extracted from text prompts remain in their distinct semantic spaces without overlap. Consequently, in this way, we can simultaneously achieve style and content control during generation without any interference.


Another challenging aspect is how to obtain accurate style representation from a single reference image, as most existing methods <cit.> simply using the coarse-grained supervision trained CLIP encoder struggle with independent style control.
To address this, we have developed a style-focused dataset with over 300 style categories and 30,000 images, all professionally annotated. 
In addition, based on the tokenization method we analyzed in the previous paragraph for precise control and decoupling, we have trained a style-specific embedding extractor, enhanced by contrastive learning, to distinguish and represent style nuances. This refinement boosts the encoder's adaptability to new styles and overall robustness.


Our contributions can be summarized as follows: 


  ∙ We introduce StyleTokenizer, a novel method for style control in diffusion models. This approach allows for accurate style control of generated images using a single arbitrary reference image in a training-free manner, while minimizing the impact on the control effectiveness of text prompts. Experimental results demonstrate the outstanding performance of our proposed method compared to other state-of-the-art approaches in this field.

  ∙ We curate a Style30k dataset comprising over 300 widely distributed style categories, manually collected by professional designers. This dataset includes a total of 30,000 images and, to the best of our knowledge, is currently the largest and most diverse open-source style dataset available. Using this dataset, we train a robust style encoder capable of effectively representing style information based on a single reference image.




§ RELATED WORKS





 §.§ Text-to-Image synthesis


Text-to-image synthesis has experienced a phenomenal technological breakthrough in recent years.
DALL-E 1, 2, 3 <cit.> has demonstrated impressive results in text-to-image synthesis by utilizing a text encoder to control auto-regressive transformers and diffusion models. This led to substantially refined and high-visual-quality synthetic images. Stable Diffusion <cit.> and Imagen <cit.> have also shown promising results in text-to-image synthesis by leveraging diffusion models.
Furthermore, StyleGAN-T <cit.> has explored the potential of GANs in text-to-image synthesis and demonstrated remarkable results. These approaches typically involve using text encoders like CLIP <cit.> and GPT <cit.> and subsequently controlling the generators.
There are many attribute control methods derived from text-to-image generation models. ControlNet <cit.> incorporated additional control features into Unet's feature space. Composer <cit.> added extra feature inputs to cross attention and time embedding. Text inversion <cit.> and blip-diffusion <cit.>, on the other hand, controlled attributes by introducing novel text embeddings. These methods have greatly advanced the field of text-to-image synthesis.



 §.§ Style Control in Image Generation


Style is a quite subtle attribute of images that is hard to define or even describe by people. 
Even though style control has been widely adopted in diverse applications, such as design and short video entertainment, it involves considerable efforts including scaffolding tuning and try-and-error from users. Gatys <cit.> proposed the use of VGG and Gram matrix to extract style features for loss supervision. CycleGAN <cit.> and StarGAN <cit.> established cycle mechanisms to achieve style transfer with a limited set of styles while keeping the content intact. BlendGAN <cit.> employed an additional style encoder to control StyleGAN <cit.> for zero-shot style transfer on face datasets. CAST <cit.> utilized a contrastive loss to extract image styles. ALADIN <cit.> used the AdaIN <cit.> module to extract styles and control the decoder for style image generation. Wu <cit.> attempted to extract style information from visual features by aligning the generated images from diffusion with the style and content components of the prompt. 
Some methods leverage prior knowledge by assuming that styles mainly reside in certain feature categories to achieve style control. DiffStyle <cit.> combined diffusion models of both style and content during denoising. ProsPect <cit.> incorporated content and style reference images at different denoising stages in the diffusion process. P+ <cit.> controlled the features of Unet at different resolutions separately for content and style. SDXL <cit.> incorporated an additional prompt module that enables users to specify limited styles. Nonetheless, these prior arts still require some costly efforts of data collection or finetuning from the end user. This limitation has been resolved by our method, which involves extracting style and applying control from a single image.




§ METHODOLOGY






 §.§ Overview


Our method is derived within the Stable Diffusion framework, which decouples content and style conditions in the image generation process, resulting in visually appealing and coherent outputs. In this section, we introduce the overall pipeline of our method. 

Compared with the traditional Stable Diffusion framework, we introduce two novel modules, as illustrated in Fig. <ref>, a Style Encoder for style representation and a Style Tokenizer for style control. These two modules are trained in two stages. In the first stage, the Style Encoder is trained on a style dataset named Style30K to acquire style representation capability. In the second stage, style representations are extracted from reference images by Style Encoder, and Style Tokenizer learns to convert them into style tokens, which are aligned with text tokens in the word embedding space. Finally, both text tokens and style tokens are concatenated and input to the SD pipeline as a condition to generate the image.



 §.§ Style30K Dataset




Describing the style of an image verbally is even challenging for artists. The meaning of image style is very rich and subtle, encompassing various perspectives, such as color distribution, lighting, line styles, artistic styles, brushwork, emotions, etc. These characteristics are visually perceptible but difficult to precisely and comprehensively describe in language. Therefore, extracting features directly from images is a more reasonable choice, rather than relying on text. Existing feature extraction methods often rely on generic semantics or classification features and are not specifically trained for style-related tasks. Hence, we construct a style dataset named Style30K to train a style encoder that focuses on capturing style-oriented features, shown in Fig. <ref>.

While it is challenging to describe image styles in language, people can intuitively judge whether two images share the same style or not. Therefore, we adopt a semi-manual approach to construct the dataset. The collection process of Style30K consists of three stages. In the first stage, we gather images with various styles, where each style is represented by three sample images as queries. Subsequently, we use different embedding extractors to extract the embedding of these queries and perform retrieval within a large dataset. In the second stage, we manually filter and collect images from the retrieval results that share the same style as the three queries for each style category. Each collected image requires a consensus among three annotators for it to be included. In the third stage, we annotate each collected image with a content prompt using CogVLM <cit.>. In detail, the image and the instruction of "Describe the image, only the content of the image, do not include the style of it." are input into the caption model, which yields captions that are solely related to the content of the image. The reason for this way is to ensure that style and content control signals are independent to each other. During the model's training, the prompt provides information related only to content, while the style is provided by the Style Tokenizer.





 §.§ Style Encoder

In this section, we describe the process of training the Style Encoder ℰ_s, which extracts the style cue from images I_s and encodes it into style embedding f_s. This embedding is then used to guide the generation process. 

Obtaining accurate style representation from a single reference image is a challenging task. Previous methods extract image representation from the CLIP image encoder to enable content and style control. This approach has shown promising results in providing effective control over various visual aspects, including color, subject, layout, and more. However, it lacks the ability to independently control these aspects, particularly style control, as CLIP is trained using coarse-grained semantic information as supervision. 

To address this limitation, we use the well-labeled style dataset Style30K to train a style representation extractor capable of accurately representing style while excluding other content information. Given that the style data includes an accurate category label, the style encoder is trained using supervised representation learning. It enforces the model to only focus on category-related information (style) and ignore category-irrelevant information (content). To further enhance the generalization of the style encoder, we employ contrastive loss for supervision. As shown in the left of Fig.<ref>, it allows the model to focus on the distance differences between diverse styles. Different images of the same style are clustered together in the embedding space, images of similar styles are closer, while images of different styles are scattered. This approach enhances the robustness of the style encoder in processing new styles and improving its ability to handle novel style variations.




 §.§ Style Control


Previous adapter-based methods have the capability of image prompting in the diffusion model. It significantly enhances the ability to generate content that cannot be described in a prompt. These methods incorporate style representation into the Unet module using an additional cross-attention layer. However, they apply text and style conditions simultaneously during the denoising process, which may cause interference between the controls and loss of semantics.

Representations from the word embedding space of SD have rich style control capabilities. On the one hand, Dreambooth <cit.> and Textual Inversion <cit.> have demonstrated that new word embedding outside the existing dictionary can express diverse contents. Yet, these methods require some reference images for tuning and are prone to overfitting with the specific content. On the other hand, carefully crafted descriptions by prompt experts can also yield desired image styles. However, directly using textual descriptions to control the style is still challenging. The text descriptions used during the training of SD lack a detailed description of the style for each image. Besides, image styles encompass a wide range of aspects that are difficult to fully express in natural language. 

Therefore, we aim to find a comprehensive and accurate style description that can be applied to each image and is acceptable by diffusion pipelines. Considering that our Style Encoder is already capable of extracting a unique style embedding for any given image, a reasonable approach is to map these styles to representations in the space of word embedding. We utilize a 2-layer MLP named Style Tokenizer T_s to implement this mapping. The Style Tokenizer T_s takes the embedding f_s extracted by the Style Encoder ℰ_s and maps them into style embedding tokens e_s. In the training process, the parameters of the original SD model are frozen, and only the parameters of Style Tokenizer are updated, enabling the mapped embedding e_s to provide a comprehensive and precise representation of image styles. The style embedding e_s is concatenated with word embedding tokens e_t following Eq. <ref> and then fed into SD's text encoder. By doing so, style images can be used as a style prompt when generating images to better describe the style. Besides, the style from reference images and content extracted from text prompts remain in their distinct semantic spaces without overlap. 


    e_ts = [e_start,e_s,e_t,e_end],

where e_s = T_s(f_s).

During the inference process, we employ the classifier-free guidance <cit.>. In order to independently control the weight of both text and style, we adopt a similar approach as InstructPix2Pix <cit.>, as described in Eq. <ref>. 


    ẽ_θ(z_t, c_t, c_s)    = e_θ(z_t, ∅, ∅) 
        + s_t · (e_θ(z_t, c_t, ∅) - e_θ(z_t, ∅, ∅)) 
        + s_s · (e_θ(z_t, c_t, c_s) - e_θ(z_t, c_t, ∅)),

where c_t and c_s represent the text and style condition. The strength of s_t and s_s represents the intensity of the text and style condition, respectively.



§ EXPERIMENTS




 §.§ Experimental Details



We collect 10 million high-quality images on the Internet for model training. The Style Encoder adopts the visual encoder of CLIP ViT-B/32 as the pre-trained backbone. We first use these 10 million images for pre-training, and then use Style30K for supervised training. In terms of style control, we adopt SD v1.5 as the generation model. The style embedding is tokenized by the Style Tokenizer with a shape of 8×768. Then, these tokens are concatenated with text embedding tokens and fed into the text encoder of the SD pipeline.
During this stage, all the images are used for training the Style Tokenizer. When the denoising target image I is from the Style30K dataset, the style reference image I_s is randomly selected from the images within the same style category as I. Otherwise, when I does not have style annotation, the style reference is I itself.





 §.§ Qualitative Evaluation


To facilitate a comparison with other methods, we conducted a test on both our method and the previous approaches, including StyTr^2<cit.>, InST<cit.>, CAST<cit.>, SD<cit.> controlled by style prompt, and IP-Adapter<cit.>. To evaluate the performance of these methods in both style control and prompt following, we prepare a benchmark consisting of 52 prompts and 28 style reference images, these prompts are from the settings used in the StyleAdapter <cit.>. The prompts encompass a rich variety of content, including human, animal, object, and scene. The reference images cover some common styles as well as some that are difficult to describe in words. Note that both of them are excluded from the training process. Our aim with the aforementioned setup is to comprehensively evaluate the strengths and weaknesses of the different methods. Some images generated by these methods can be viewed in Fig.<ref>, where each column represents the results produced by different methods using the same prompt and reference image. Below, we provide a detailed analysis of the experimental results.

As shown in Fig.<ref>, StyTr^2 and InST achieve relatively similar performance, successfully capturing the dominant color palette of the reference images. However, their grasp of the overall style such as texture is not very well. As seen in column H, they capture the red color information from the reference image but fail to comprehend the cut-paper style. Furthermore, their image quality is generally inferior to that of other methods. Utilizing style prompts for control facilitates a certain level of style control in simpler style categories, like oil and ink wash paintings, but the absence of a reference image as input led to significant discrepancies in the finer details. For more complex styles that are difficult to articulate, their ability to control style is lost. IP-Adapter produces images with a style very close to the original, but in most cases, it struggles to decouple the content from the reference image, leading to poor prompt-following ability. For instance, in columns B and E, although mountains and sunflowers are generated, the human from the reference images also appear in the output. IP-Adapter's strengths are mainly in image variation and image editing. In contrast, our method demonstrates a high degree of consistency with the reference image in terms of style, including line, texture, color, emotion, and more. It also shows a strong advantage in following text prompts. Moreover, the overall aesthetic quality of the images is superior to that of the previous methods.




 §.§ Quantitative Evaluation







In this section, our method is compared with the state-of-the-art approaches using some quantitative metrics for a fair evaluation. We employ the following metrics on the images generated in the Sec.<ref> to evaluate the quality and effectiveness of the generated images:

Text-Image Similarity. We use the CLIP model to extract embedding from generated images and their corresponding text prompts. Then cosine similarity between embedding from the prompt and the generated image is calculated. Higher cosine similarity indicates better capability of the instruction following.

Aesthetic Score.
To assess the aesthetic quality of the generated images, we predict the aesthetic score for each generated image with LAION-Aesthetics Predictor <cit.>. This metric measures the visual appeal and artistic quality of the image. A higher aesthetic score indicates a visually pleasing image.

Style Similarity.
Since there is no generally accepted method for assessing style similarity, we imitate the text-image similarity metric calculated by CLIP. Style embedding of both the style reference image and the generated image are exacted by Style Encoder. After that, we compute their cosine similarity. A higher cosine similarity indicates better control of the desired style in the generated images.

User Study.
To assess the style similarity more comprehensively, we conduct user studies. For the generated images produced by each method, we have 20 users (10 professional designers and 10 users) vote anonymously for the image that they believe has the most similar style to the reference image. 

The normalized votes (vote rate), serve as the style similarity score.

For each of these metrics, we calculate the average across all generated results to provide an overall evaluation of the performance of the existing style control models. Experimental results are summarized in Tab. <ref>, where we compare our method with the SOTA approaches using the aforementioned evaluation metrics. 
Our method significantly outperforms other SOTA approaches in terms of style similarity. In the user study, our method also receives more votes than other methods. These results highlight the effectiveness of our approach in preserving the desired style in the generated images. Furthermore, our method is trained on large-scale high-aesthetic data and thus achieves a higher aesthetic score than the base SD model. As shown in Fig.<ref>, it brings better results in terms of aesthetics than other methods. As for the instruction following, the text-image similarity of our method has comparable performance with the base SD model. It shows that our method does not lead to a decrease in the ability to follow instructions during style control. In summary, the experimental results demonstrate that our method can achieve better style control capability and generate visually appealing images, while the instruction following is not affected by this.




 §.§ Evaluation of Style Encoder


We conduct an evaluation of our Style Encoder and compare it with several publicly available feature encoders, namely CLIP <cit.>, VGG <cit.> and BlendGAN <cit.>. The evaluation is performed on a validation set of Style30K, consisting of 12 different style categories with a total of 900 images that are non-repetitive with the training style categories.





We use different methods to extract the style embedding of each image in the validation set, and then visualize the distribution of these embeddings in the representation space, as shown in Fig. <ref>. Style embeddings belonging to different categories are represented by points of different colors and distributed in their own clusters at different locations in space. Our Style Encoder demonstrates the ability to effectively cluster images belonging to the same style category, resulting in compact intra-class distances and large inter-class differences. It indicates that our method has a better ability to present style from images and is robust enough to handle novel style variations.
Additionally, we perform quantitative evaluation by Silhouette Coefficient <cit.> and Calinski-Harabasz metrics <cit.> in Tab. <ref> used to evaluate 
the effect of clustering. Both visual results and cluster metrics demonstrate that our method effectively extracts features with better clustering results for images with the same styles compared with other extractors.








 §.§ Ablation Studies


In this section, we conduct ablation studies to assess the effectiveness of our Style Encoder and Style Tokenizer in Fig. <ref> and Table  <ref>. Fig. <ref>(b) represents that style embedding is not first aligned to the word embedding space by the style tokenizer, but is directly concatenated with text embedding. 
Fig. <ref>(c) represents that the style encoder is not used for style representation, but the CLIP visual encoder is used directly to encode the image. 
Experimental results show that if any one of them is missing, the generated images either have a weakened ability to follow instructions or have poor style consistency.




 §.§ Other Application
 


Since our method can maintain the style in the reference image, if multiple images of different styles are used as references, the fusion between styles produces new styles. We use two styles for blending style in Fig.<ref>. By starting with the palette style as a control and gradually incorporating the sketch style, the images that are generated show a progressive transition from the palette to the sketch style. 





§ CONCLUSION

In this work, we propose a novel zero-shot method to precisely control the style of generated images from diffusion models. In order to decouple style and content conditions, we first construct a fine-labeled style dataset called Style30K and propose a Style Encoder that can extract style representation from reference images. Then we propose a Style Tokenizer to align style and text tokens in a uniform space. Finally, the aligned tokens are used as a condition in the denoising process of the diffusion model. Our method offers a flexible and effective solution for incorporating style control in image generation, opening up new possibilities for generating high-quality stylized content.











splncs04


