Vector Grimoire: Codebook-based Shape Generation under Raster Image Supervision

Marco Cipriano, Moritz Feuerpfeil, Gerard de Melo

Vector Grimoire (GRIMOIRE) is a novel text-to-SVG generative framework that learns to create scalable vector graphics using only raster image supervision. By combining a discrete "visual alphabet" of vector strokes with an autoregressive transformer, it bypasses the need for scarce SVG training data and produces high-quality, editable graphics significantly faster than optimization-based methods.

Introduction

Generating Scalable Vector Graphics (SVG) is notoriously difficult for AI. Unlike raster images, which are simple grids of pixels, SVGs are composed of mathematical paths and shapes. Most current models rely on "direct supervision," meaning they must be trained on massive datasets of raw SVG code. However, high-quality SVG data is scarce compared to the trillions of raster images available online.

Furthermore, existing SVG models often struggle with visual attributes like stroke width and color, or they require heavy pre-processing to "tokenize" complex vector commands. GRIMOIRE addresses this by asking a fundamental question: Can we build a model that learns the underlying geometry of vector art just by looking at regular pixel-based images?

Methodology

The authors propose a two-stage pipeline to bridge the gap between pixels and vectors:

  1. The Visual Shape Quantizer (VSQ): This module acts as a specialized Vector Quantized Variational Autoencoder (VQ-VAE). An encoder takes a small patch of a raster image and maps it to a discrete "codebook"—a finite set of learned vector primitives. Crucially, the decoder is a differentiable rasterizer (DiffVG). It takes the vector parameters and "paints" them back into pixels, allowing the model to calculate loss by comparing the reconstructed pixels to the original ones. To prevent messy, overlapping lines, a geometric constraint encourages the smooth, regular placement of Bézier control points.
  2. The Auto-Regressive Transformer (ART): Once the "visual alphabet" of strokes is learned, this module learns how to arrange them. It models the joint probability of shape tokens (from the codebook), their 2D positions on a canvas, and textual descriptions using BERT embeddings.
Generated icons demonstrating patch-based composition

At inference time, a prompt like "The icon of a clock" is fed into the ART, which predicts a sequence of strokes and positions. The VSQ decoder then renders these as a clean, editable SVG. Breaking images into patches makes the vectorization task manageable and allows the codebook to act as a reusable library of strokes.

Key Insights

  • Raster-to-Vector Bridge: The core innovation is using the differentiable rasterizer as a bridge. It allows the model to "imagine" a vector path and see if it matches the target pixels, effectively learning vectorization without ever seeing a line of SVG code during training.
  • Flexibility via Modularity: Because the VSQ and ART are separate, the model is highly extensible. The architecture can easily accommodate additional "heads" to predict stroke width and color without changing the core framework.
  • Speed vs. Quality: Unlike "Score Distillation Sampling" (SDS) methods that optimize a single image for hours, GRIMOIRE is a feed-forward generative model that produces results in seconds.

Results

The model was evaluated across four diverse datasets: MNIST (filled shapes), Fonts (outline strokes), FIGR-8 (complex icons), and Emoji (multi-layered, colorful shapes).

Comparison of GRIMOIRE (Ours) vs. Im2Vec on star and letter shapes
  • Superior Quality: On the FIGR-8 icon dataset, GRIMOIRE achieved an FID of 0.64 and a CLIPScore of 29.00, significantly outperforming previous image-supervised baselines like Im2Vec. The visual fidelity of the generated shapes is markedly cleaner and more structurally sound.
  • Efficiency: GRIMOIRE generates icons in approximately 2.34 seconds on an NVIDIA H100, making it roughly 50x to 150x faster than optimization-based competitors like VectorFusion or CLIPDraw.
  • Zero-Shot Transfer: The VSQ module demonstrated impressive robustness. A VSQ trained on icons could reasonably reconstruct font characters it had never seen before, proving it had learned a generalized "language" of strokes.

Limitations and Future Work

Because the transformer predicts patches independently, the final SVG can sometimes look fragmented where segments meet. While the authors use post-processing (Path Clipping and Interpolation) to stitch lines together, achieving global coherence natively remains a target for future work. Additionally, scaling this patch-based autoregressive approach to highly complex, multi-object scenes presents an ongoing challenge.

Overall, Vector Grimoire represents a significant step toward democratizing vector generation, proving that machines can learn the art of the curve without relying on massive, hard-to-source SVG datasets.

Summary updated

BibTeX
@inproceedings{cipriano2025vector,
  author = {Marco Cipriano and Moritz Feuerpfeil and Gerard de Melo},
  title = {{Vector Grimoire: Codebook-based Shape Generation under Raster Image Supervision}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=xYtLsWiUli},
}
Figure