jennyxue's picture
Model card and the original license
eaf2523 verified
|
Raw History Blame Contribute Delete
23.5 kB
metadata
base_model: starvector/starvector-1b-im2svg
base_model_relation: quantized
license: apache-2.0
pipeline_tag: image-to-text
library_name: onnx
tags:
  - onnx
  - moonbox
  - onnxruntime
  - starvector
  - svg
  - image-to-svg
  - vectorization
  - starcoder

StarVector 1B ONNX

ONNX builds of StarVector 1B, made by Moonbox for on-device use with ONNX Runtime (CPU, CUDA, DirectML). Each precision is one folder holding the graphs and a small Python pipeline.py that does the rest (image preprocessing, prompt, positions, decoding loop); what the graphs take and return is under How to run.

Files

The last column is the benchmark against the original model (details under How to run): character error rate of the recognised text against the page's text, per language, and against the original's own output.

Precision File Size sha256 Benchmark
fp16 fp16/added_tokens.json 0.1 kB f2d12193cf6b rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/decoder.onnx 67.4 MB 6be1f4ea600f rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/decoder.onnx.data 2.27 GB 3c7a0472e77e rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/embed.onnx 201.3 MB 4d6003d10fdd rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/image.onnx 594.3 MB 08c61759bde2 rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/merges.txt 0.4 MB 303127a244b0 rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/pipeline.py 4.8 kB 8cc8f97ff339 rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/preprocessor_config.json 0.2 kB b8830fd041a6 rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/processor_config.json 0.2 kB fb904bfccb24 rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/special_tokens_map.json 1.0 kB f67ded3cf1e1 rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/tokenizer.json 3.5 MB 677ed0fa17c7 rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/tokenizer_config.json 4.9 kB e6f6894916d1 rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
fp16 fp16/vocab.json 0.8 MB 20175afb9f16 rendering PSNR vs the icon 13.9 dB (original 14.4, fp16); 1/8 SVGs identical; 30.9 s per icon (CUDA)
int8 int8/added_tokens.json 0.1 kB f2d12193cf6b rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/decoder.onnx 67.5 MB 6e2fa6e348d2 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/decoder.onnx.data 1.22 GB d29bb20747ca rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/embed.onnx 100.8 MB fc4ac1413a60 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/image.onnx 300.3 MB 94a025de0c6c rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/merges.txt 0.4 MB 303127a244b0 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/pipeline.py 4.8 kB 8cc8f97ff339 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/preprocessor_config.json 0.2 kB b8830fd041a6 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/processor_config.json 0.2 kB fb904bfccb24 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/special_tokens_map.json 1.0 kB f67ded3cf1e1 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/tokenizer.json 3.5 MB 677ed0fa17c7 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/tokenizer_config.json 4.9 kB e6f6894916d1 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int8 int8/vocab.json 0.8 MB 20175afb9f16 rendering PSNR 14.3 dB; 3/8 SVGs identical; 39.0 s per icon (CUDA)
int4 int4/added_tokens.json 0.1 kB f2d12193cf6b below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/decoder.onnx 67.5 MB 12e88b752644 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/decoder.onnx.data 664.6 MB 6d8639d39c80 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/embed.onnx 100.8 MB fc4ac1413a60 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/image.onnx 300.3 MB 94a025de0c6c below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/merges.txt 0.4 MB 303127a244b0 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/pipeline.py 4.8 kB 8cc8f97ff339 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/preprocessor_config.json 0.2 kB b8830fd041a6 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/processor_config.json 0.2 kB fb904bfccb24 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/special_tokens_map.json 1.0 kB f67ded3cf1e1 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/tokenizer.json 3.5 MB 677ed0fa17c7 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/tokenizer_config.json 4.9 kB e6f6894916d1 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)
int4 int4/vocab.json 0.8 MB 20175afb9f16 below threshold (experimental): rendering PSNR 12.3 dB; 0/8 identical; 43.3 s per icon (CUDA)

How to run

StarVector 1B (im2svg) (ServiceNow / StarVector: image-to-SVG generation; a CLIP image encoder and an adapter feed a StarCoderBase-1B code model fine-tuned to write SVG) as three ONNX graphs plus pipeline.py, a numpy runtime that reproduces the repository's processor and generate_im2svg (greedy) around them. The decoder is a fine-tune of bigcode/starcoderbase-1b, whose own license is the BigCode OpenRAIL-M agreement (use restrictions in its Attachment A); StarVector's card states Apache-2.0.

  • image.onnx: image [1, 3, 224, 224] (normalised) -> prefix [1, 257, 2048] (the CLIP ViT, ln_vision and the adapter).
  • embed.onnx: input_ids [1, S] -> inputs_embeds [1, S, 2048].
  • decoder.onnx: the StarCoderBase-1B decoder (GPTBigCode, 24 layers, multi-query attention, learned positions), fp16: inputs_embeds, position_ids [1, S], past_key_values.{0..23} [1, P, 256] (key and value side by side, as GPTBigCode caches them) -> logits of the last position [1, 49156] and present.* (the whole cache).

pipeline.py pads the image to a square (white), resizes it (bicubic) to 224 and applies CLIP's mean / std. It puts "<svg" after the image prefix and decodes greedily until </svg> or the end token. It needs numpy, onnxruntime (or onnxruntime-gpu), tokenizers and Pillow:

import sys
from PIL import Image
sys.path.insert(0, "int8")
import pipeline
sv = pipeline.StarVector("int8", "cuda")
open("icon.svg", "w").write(sv(Image.open("icon.png")))

The official generation samples (nucleus 0.9, 2 beams by default). This runtime decodes greedily. The model works best on icons and simple flat graphics. On Windows, give CUDA sessions the run option memory.enable_memory_arena_shrinkage = gpu:0, as pipeline.py does. Every input length differs, so ONNX Runtime's GPU arena otherwise keeps growing.

Precisions. fp16/: the image graph fp16 math with fp32 inputs / outputs, the embedding fp16, the decoder fp16 (exported from the float16 model, as it ships). int8/: the image graph weight-only int8, the embedding int8 per row, the decoder 8-bit MatMulNBits (block 32, from the fp16 graph). int4/ (below threshold, experimental): the decoder 4-bit MatMulNBits, the rest as int8/. No bf16: fp16 passes.

Benchmark. Eight synthetic icons (flat shapes on white, 256 px, drawn for this test). The original is the repository's generate_im2svg with nucleus sampling off and one beam (greedy), in float16 on CUDA. The builds get the same preprocessed image. Greedy SVG text diverges after small numeric differences in such long outputs, so text identity says little. The score is how well each output's rendering (resvg, 256 px) matches the input icon: PSNR, averaged over the eight. An SVG that doesn't render (cut off at the length limit) counts as 0 dB. The original's own output doesn't render for three of the eight. Pass (first measurement): mean PSNR at most 1 dB below the original's.

mean PSNR of the rendering vs the icon SVGs identical to the original's text similarity to the original's seconds per icon
original (PyTorch fp16, CUDA) 14.4 dB 8 / 8 1.00 18.3
fp16/ (CUDA) 13.9 dB 1 / 8 0.80 30.9
int8/ (CUDA) 14.3 dB 3 / 8 0.84 39.0
int4/ (CUDA), below threshold 12.3 dB 0 / 8 0.42 43.3

Graphs checked against the original modules before the benchmark (largest absolute difference): image 1.1e-4 of 34.7 (float32); decoder 7.6e-6 of 16.2 against the model's own forward in float32, and the float16 graph 0.03 of 12.4. pipeline.py copies the KV cache between host and GPU every step; that is most of why it is slower than PyTorch here.

How these were made

From StarVector 1B at revision 380ab95d25. The graphs were exported from the original PyTorch modules with torch.onnx (opset 17) and checked against them. Weight-only quantization: int8 is a per-output-channel int8 weight behind DequantizeLinear, int4 is ONNX Runtime's MatMulNBits (block 32). Each card above says which precision every graph uses. Every precision was benchmarked against the original before upload (pass: per language, character error rate at most 1 point above the original's), and the sha256 column above is what the files must hash to.

License

Apache-2.0. These files are a derivative of the original model and carry its license: it is copied in this repository, and it governs your use of these files. The original model card follows unchanged.


Original model card

Model Card for StarVector

image/png

StarVector is a foundation model for generating Scalable Vector Graphics (SVG) code from images and text. It utilizes a Vision-Language Modeling architecture to understand both visual and textual inputs, enabling high-quality vectorization and text-guided SVG creation.

Model Details

Model Description

This is the model card for the StarVector model, a 🤗 transformers model. StarVector is a foundation model for generating Scalable Vector Graphics (SVG) code from images and text. It utilizes a Vision-Language Modeling architecture to understand both visual and textual inputs, enabling high-quality vectorization and text-guided SVG creation.

  • Developed by: ServiceNow Research, Mila - Quebec AI Institute, ETS, Montreal.
  • Shared by : Juan A Rodriguez, Abhay Puri, Shubham Agarwal, Issam H. Laradji, Sai Rajeswar, Pau Rodriguez, David Vazquez, Christopher Pal, Marco Pedersoli.
  • Model type: Vision-Language Model for SVG Generation.
  • Language(s) (NLP): English.
  • License: Apache 2.0

Model Architecture

The StarVector architecture integrates an image encoder and a Large Language Model (LLM) Adapter to generate SVG code from both image and text inputs. Images are first converted into embeddings using a Vision Transformer (ViT), after which the LLM Adapter maps these embeddings into the LLM's embedding space to create visual tokens. Text prompts are handled through the LLM’s tokenizer and embedder. This unified multimodal approach ensures precise and contextually rich SVG output.

Figure 2: StarVector Architecture
Figure 2: a) StarVector Architecture: StarVector projects images into embeddings via an image encoder, then maps these embeddings to the LLM hidden space using an LLM Adapter, generating Visual Tokens. Text conditioning is achieved with the LLM's tokenizer and embedder. The model learns to map token sequences (visual or textual) to SVG code. The symbol ⊕ denotes mutually exclusive operations (image-to- SVG or text-to-SVG), while ‖ indicates sequence concatenation. Figure 2: b)Vision Model and Adapter: The image encoder employs a Vision Transformer (ViT) to process image patches sequentially. The LLM Adapter non-linearly projects embeddings into visual tokens for LLM integration.

Model Sources

Uses

Direct Use

Image-to-SVG generation, Text-to-SVG generation.

Downstream Use

Creation of icons, logotypes, technical diagrams, and other vector graphics.

Out-of-Scope Use

Generating realistic photographic images or complex 3D graphics.

Bias, Risks, and Limitations

Potential biases may exist in the model due to the composition of the training data (SVG-Stack). The model's ability to perfectly vectorize all types of images and interpret all textual instructions may have limitations. Users should be aware of these potential issues, especially in critical applications.

Recommendations

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. Further investigation into the model's behavior across different types of inputs is recommended.

How to Get Started with the Model

Use the code below to get started with the model.

from PIL import Image
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoProcessor
from starvector.data.util import process_and_rasterize_svg
import torch
 
model_name = "starvector/starvector-1b-im2svg"
 
starvector = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, trust_remote_code=True)
processor = starvector.model.processor
tokenizer = starvector.model.svg_transformer.tokenizer
 
starvector.cuda()
starvector.eval()
 
image_pil = Image.open('assets/examples/sample-18.png')
 
image = processor(image_pil, return_tensors="pt")['pixel_values'].cuda()
if not image.shape[0] == 1:
    image = image.squeeze(0)
batch = {"image": image}
 
raw_svg = starvector.generate_im2svg(batch, max_length=4000)[0]
svg, raster_image = process_and_rasterize_svg(raw_svg)

Training Details

Training Data

SVG-Stack: A dataset of over 2 million SVG samples.

Training Procedure

The model utilizes a Vision-Language Modeling architecture. Images are projected into embeddings via an image encoder, then mapped to the LLM hidden space using an LLM Adapter, generating Visual Tokens. Text conditioning is achieved with the LLM's tokenizer and embedder. The model learns to map token sequences (visual or textual) to SVG code.

Evaluation

Testing Data & Factors

Testing Data

SVG-Bench

Factors

SVG-Stack, SVG-Fonts, SVG-Icons, SVG-Emoji, SVG-Diagrams.

Models

StarVector models achieve state-of-the-art performance on SVG generation tasks

We provide Hugging Face 🤗 model checkpoints for image2SVG vectorization, for 💫 StarVector-8B and 💫 StarVector-1B. These are the results on SVG-Bench, using the DinoScore metric.

Method SVG-Stack SVG-Fonts SVG-Icons SVG-Emoji SVG-Diagrams
AutoTrace 0.942 0.954 0.946 0.975 0.874
Potrace 0.898 0.967 0.972 0.882 0.875
VTracer 0.954 0.964 0.940 0.981 0.882
Im2Vec 0.692 0.733 0.754 0.732 -
LIVE 0.934 0.956 0.959 0.969 0.870
DiffVG 0.810 0.821 0.952 0.814 0.822
GPT-4-V 0.852 0.842 0.848 0.850 -
💫 StarVector-1B 0.926 0.978 0.975 0.929 0.943
💫 StarVector-8B 0.966 0.982 0.984 0.981 0.959

Note: StarVector models will not work for natural images or illustrations, as they have not been trained on those images. They excel in vectorizing icons, logotypes, technical diagrams, graphs, and charts.

As shown in the table above, StarVector-8B achieves the highest performance across all benchmark datasets, demonstrating its effectiveness in generating high-quality SVG code from images. The model's ability to understand and reproduce complex vector graphics makes it particularly valuable for applications requiring precise vectorization of icons, logos, and technical diagrams.

Summary

StarVector represents a significant advancement in the field of vector graphics generation. By combining the power of vision-language models with a comprehensive training dataset, we've created a system that can accurately translate images into high-quality SVG code. The model's performance on SVG-Bench demonstrates its effectiveness across a wide range of vector graphics tasks.

We believe that StarVector will enable new applications in design, illustration, and technical documentation, making vector graphics more accessible and easier to create. We invite the research community to build upon our work and explore new directions in this exciting field.

For more details, please refer to our paper and explore our code repository.

BibTeX entry and citation info

@misc{rodriguez2024starvector,
      title={StarVector: Generating Scalable Vector Graphics Code from Images and Text},
      author={Juan A. Rodriguez and Abhay Puri and Shubham Agarwal and Issam H. Laradji and Pau Rodriguez and Sai Rajeswar and David Vazquez and Christopher Pal and Marco Pedersoli},
      year={2024},
      eprint={2312.11556},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2312.11556},
}