Stylecodes: Encoding Stylistic Information For Image Generation

Ciara RowlesarXiv 2024 · DOI

Abstract

Stylecodes introduces an open-source framework to compress complex image styles into compact, 20-symbol base64 strings. By utilizing a custom latent autoencoder and a Stylecode-conditioned control module, researchers can now share and apply specific artistic aesthetics across diffusion models as easily as sharing a URL. This method addresses the "social friction" of sharing bulky embedding files while providing a transparent alternative to closed-source style-reference systems.

Introduction

While diffusion models like Stable Diffusion have revolutionized image generation, controlling their output via text—often called "prompt engineering"—remains notoriously finicky, particularly regarding specific artistic styles. Existing solutions like IPAdapter or ControlNet allow for image-based conditioning, but they present a logistical challenge: to share a style, users must exchange the original image or a large embedding file.

MidJourney popularized a solution called srefs (style-reference codes), which are short numeric strings representing a style. However, srefs are closed-source; users cannot generate them from their own images, and the underlying architecture remains a "black box." Stylecodes proposes an open-source alternative that provides the same portability and ease of use, allowing for the extreme compression of artistic flair into a 20-character string.

Methodology

The authors developed a two-part architecture designed to work with a frozen Stable Diffusion 1.5 base model without requiring retraining of the core weights.

  1. The Style Encoder: Instead of using standard CLIP, the researchers utilized SigLip to extract image embeddings, noting it trained faster and performed better for style-specific tasks. These embeddings pass through three attention layers and are projected down to a tiny 20-dimensional bottleneck.
  2. The StyleCode: This 20-dimensional vector is quantized and converted into a 20-symbol base64 string (plus one extra digit for versioning). This makes the style highly portable and easy to share in text format.
  3. The Control Module: To apply the style, a decoder takes the 20-digit latent and transforms it into a shape that matches the midblock states of the UNet. This functions as a "decoder-only" version of ControlNet, residually affecting the base model's hidden states.
The Stylecode pipeline: A style image is processed by the Style Encoder into a compact string, which then conditions the Control Model to generate a new image based on a text prompt.

To ensure smooth training, the authors bypassed the base64 discretization step during backpropagation, allowing gradients to flow through the continuous latent space before applying the bottleneck constraints.

Dataset and Training

The researchers generated a custom dataset of 35,000 entries using a synthetic pipeline to ensure high-quality style examples. Source images were pulled from MidJourney and CommonCanvas, then stylized using InstantStyle with SDXL IPAdapter. Prompts were randomly sampled from the JourneyDB dataset. While originally 1024x1024, the images were downscaled to 512x512 to match the native resolution of Stable Diffusion 1.5.

Results and Discussion

The paper demonstrates that extreme compression is viable: a mere 20 dimensions are sufficient to capture the essence of an artistic style. This suggests that "style" occupies a much lower-dimensional manifold than the actual content of an image.

A demonstration of the Stylecode framework applying a retro-futuristic aesthetic from a source image to a new prompt of a car on a mountain road.

Quantitatively, experiments show that this compression results in minimal loss in quality compared to traditional techniques using full-resolution embeddings. Furthermore, because the base model remains frozen, StyleCodes are "plug-and-play" compatible with community-tuned models like Anything v3 or Realistic-Vision.

Limitations and Future Work

Despite its success on SD 1.5, scaling this architecture to larger Diffusion Transformer (DiT) models like SD3 or Flux remains computationally expensive. The current model also faces some dataset bias due to the limited range of the training data. Future work will focus on improving diversity through a mix of real-world and synthetic data, as well as exploring how StyleCodes interact with Classifier-Free Guidance (CFG) for multi-style blending.

Summary updated

BibTeX
@misc{rowles2024stylecodes,
  author = {Ciara Rowles},
  title = {{Stylecodes: Encoding Stylistic Information For Image Generation}},
  year = {2024},
  eprint = {2411.12811},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.12811},
}
Figure