star-vector

joanrodApache-2.0长期未更新

把位图转成 SVG 的视觉语言基础模型,将矢量化当作代码生成任务,输出高精度、可直接使用的 SVG 代码。

StarVector is a foundation model for SVG generation that transforms vectorization into a code generation task. Using a vision-language modeling architecture, StarVector processes both visual and textual inputs to produce high-quality SVG code with remarkable precision.

暂无版本4,639star264fork同步于 2026-11-10 17:38 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/joanrod/star-vector.git
cd star-vector
conda create -n starvector python=3.11.3 -y
conda activate starvector
pip install --upgrade pip
pip install -e .
硬件要求按 README 说明

README 示例代码调用 .cuda(),需 NVIDIA GPU;未说明具体显存要求,8B 模型建议按大模型显存预估,README 未给出明确数字

多卡 / 张量并行
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

把图像或文本转成 SVG 代码的多模态大模型,适合图标、logo、图表类矢量图生成

把位图转成 SVG 的视觉语言基础模型,将矢量化当作代码生成任务,输出高精度、可直接使用的 SVG 代码。

核心能力

  • 基于 StarCoder 的多模态架构,在 SVG 代码空间直接生成
  • 支持 image2SVG 与 text2SVG 两种生成任务
  • 提供 1B 与 8B 两个 HuggingFace 预训练权重
  • 用 SVG 图元(椭圆、多边形、文本等)生成紧凑矢量图
  • 配套 SVG-Stack 数据集与 SVG-Bench 基准评估

容易踩的坑

模型权重需从 HuggingFace 单独下载(starvector-8b-im2svg 或 1b-im2svg),仓库不含权重;训练需额外执行 pip install -e ".[train]";模型未在自然图像或插画上训练,只适合图标、logo、技术图表等

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    🔥 News

    • Sep 2025: RLRF Accepted at NeurIPS 2025,
      • Our follow-up work to StarVector, RLRF, has been accepted to NeurIPS 2025! Check out the paper [Link]
    • March 2025: StarVector Accepted at CVPR 2025,
      • StarVector has been accepted at CVPR 2025! Check out the paper [Link]
      • Check out our website for more information [Link]
      • StarVector models are now available on HuggingFace! [Link] [Link]
      • SVGBench and SVG-Stack datasets are now available on HuggingFace Datasets! [Link] [Link]

    🚀 Introduction

    StarVector is a multimodal vision-language model for Scalable Vector Graphics (SVG) generation. It can be used to perform image2SVG and text2SVG generation. We pose image generation as a code generation task, using the power of multimodal VLMs

    Abstract: Scalable Vector Graphics (SVGs) are vital for modern image rendering due to their scalability and versatility. Previous SVG generation methods have focused on curve-based vectorization, lacking semantic understanding, often producing artifacts, and struggling with SVG primitives beyond \textit{path} curves. To address these issues, we introduce StarVector, a multimodal large language model for SVG generation. It performs image vectorization by understanding image semantics and using SVG primitives for compact, precise outputs. Unlike traditional methods, StarVector works directly in the SVG code space, leveraging visual understanding to apply accurate SVG primitives. To train StarVector, we create SVG-Stack, a diverse dataset of 2M samples that enables generalization across vectorization tasks and precise use of primitives like ellipses, polygons, and text. We address challenges in SVG evaluation, showing that pixel-based metrics like MSE fail to capture the unique qualities of vector graphics. We introduce SVG-Bench, a benchmark across 10 datasets, and 3 tasks: Image-to-SVG, Text-to-SVG generation, and diagram generation. Using this setup, StarVector achieves state-of-the-art performance, producing more compact and semantically rich SVGs.

    Multimodal Architecture

    StarVector uses a multimodal architecture to process images and text. When performing Image-to-SVG (or image vectorization), the image is projected into visual tokens, and SVG code is generated. When performing Text-to-SVG, the model only receives the text instruction (no image is provided), and a novel SVG is created. The LLM is based of StarCoder, which we leverage to transfer coding skills to SVG generation.

    📖 Table of Contents

    Installation

    1. Clone this repository and navigate to star-vector folder
    git clone https://github.com/joanrod/star-vector.git
    cd star-vector
    
    1. Install Package
    conda create -n starvector python=3.11.3 -y
    conda activate starvector
    pip install --upgrade pip  # enable PEP 660 support
    pip install -e .
    
    1. Install additional packages for training
    pip install -e ".[train]"
    

    Upgrade to latest code base

    git pull
    pip install -e .
    

    Quick Start - Image2SVG Generation

    from PIL import Image
    from starvector.model.starvector_arch import StarVectorForCausalLM
    from starvector.data.util import process_and_rasterize_svg
    
    model_name = "starvector/starvector-8b-im2svg"
    
    starvector = StarVectorForCausalLM.from_pretrained(model_name)
    
    starvector.cuda()
    starvector.eval()
    
    image_pil = Image.open('assets/examples/sample-0.png')
    image = starvector.process_images([image_pil])[0].cuda()
    batch = {"image": image}
    
    raw_svg = starvector.generate_im2svg(batch, max_length=1000)[0]
    svg, raster_image = process_and_rasterize_svg(raw_svg)
    

    Use it from HuggingFace AutoModel

    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-8b-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)
    

    Models

    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.

    MethodSVG-StackSVG-FontsSVG-IconsSVG-EmojiSVG-Diagrams
    AutoTrace0.9420.9540.9460.9750.874
    Potrace0.8980.9670.9720.8820.875
    VTracer0.9540.9640.9400.9810.882
    Im2Vec0.6920.7330.7540.732-
    LIVE0.9340.9560.9590.9690.870
    DiffVG0.8100.8210.9520.8140.822
    GPT-4-V0.8520.8420.8480.850-
    💫 StarVector-1B (🤗 Link)0.9260.9780.9750.9290.943
    💫 StarVector-8B (🤗 Link)0.9660.9820.9840.9810.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.

    Datasets - SVG-Bench

    SVG-Bench is a benchmark for evaluating SVG generation models. It contains 10 datasets, and 3 tasks: Image-to-SVG, Text-to-SVG, and Diagram-to-SVG.

    See our Huggingface 🤗 Dataset Collection

    DatasetTrainValTestToken LengthSVG PrimitivesAnnotation
    SVG-Stack (🤗 Link)2.1M108k5.7k1,822 ± 1,808AllCaptions
    SVG-Stack_sim (🤗 Link)601k30.1k1.5k2k ± 918Vector path-
    SVG-Diagrams (🤗 Link)--4723,486 ± 1,918All-
    SVG-Fonts (🤗 Link)1.8M91.5k4.8k2,121 ± 1,868Vector pathFont letter
    SVG-Fonts_sim (🤗 Link)1.4M71.7k3.7k1,722 ± 723Vector pathFont letter
    SVG-Emoji (🤗 Link)8.7k6676682,551 ± 1,805All-
    SVG-Emoji_sim (🤗 Link)58057962,448 ± 1,026Vector Path-
    SVG-Icons (🤗 Link)80.4k6.2k2.4k2,449 ± 1,543Vector path-
    SVG-Icons_sim (🤗 Link)80,4352,8361,2772,005 ± 824Vector path-
    SVG-FIGR (🤗 Link)270k27k3k5,342 ± 2,345Vector pathClass, Caption

    We offer a summary of statistics about the datasets used in our training and evaluation experiments. This datasets are included in SVG-Bench. The subscript sim stands for the simplified version of the dataset, as required by some baselines.

    Training

    Confirm dependencies are installed

    pip install -e ".[train]"
    

    Set environment variables

    We recommend setting the following environment variables:

      export HF_HOME=<path to the folder where you want to store the models>
      export HF_TOKEN=<your huggingface token>
      export WANDB_API_KEY=<your wandb token>
      export OUTPUT_DIR=<path/to/output>
    

    cd the root of the repository.

    cd star-vector
    

    Image2SVG Pretraining (Stage 1)

    We have different training approaches for StarVector-1B and StarVector-8B. StarVector-1B can be trained using Deepspeed, while StarVector-8B requires FSDP.

    StarVector-1B Training

    You can use the following command to train StarVector-1B on SVG-Stack for the Image2SVG vectorization task, using Deepspeed and Accelerate

    # StarVector-1B
    accelerate launch --config_file configs/accelerate/deepspeed-8-gpu.yaml starvector/train/train.py config=configs/models/starvector-1b/im2svg-stack.yaml
    
    StarVector-8B Training

    You can use the following command to train StarVector-8B on SVG-Stack for the Image2SVG vectorization task, using FSDP and Accelerate. We provide the torchrun command to support multi-nodes and multi-GPUs.

    # StarVector-8B
    torchrun \
      --nproc-per-node=8 \
      --nnodes=1 \
      starvector/train/train.py \
      config=configs/models/starvector-8b/im2svg-stack.yaml
    

    Finetuning StarVector (Stage 2)

    After pretraining StarVector on image vectorization, we finetune it on additional SVG tasks like Text2SVG, and SVG-Bench datasets.

    Text2SVG Finetuning
    # StarVector-1B
    accelerate launch --config_file config/accelerate/deepspeed-8-gpu.yaml starvector/train/train.py config=configs/models/starvector-1b/text2svg-stack.yaml
    
    # StarVector-8B
    torchrun \
      --nproc-per-node=8 \
      --nnodes=1 \
      starvector/train/train.py \
      config=configs/models/starvector-8b/text2svg-stack.yaml
    
    SVG-Bench Finetuning
    # StarVector-1B
    accelerate launch --config_file config/accelerate/deepspeed-8-gpu.yaml starvector/train/train.py config=configs/models/starvector-1b/im2svg-{fonts,icons,emoji}.yaml
    
    # StarVector-8B
    torchrun \
      --nproc-per-node=8 \
      --nnodes=1 \
      starvector/train/train.py \
      config=configs/models/starvector-8b/im2svg-{fonts,icons,emoji}.yaml
    

    We also provide shell scripts in scripts/train/*

    Validation on SVG Benchmarks (⭐ SVG-Bench)

    We validate StarVector on ⭐ SVG-Bench Benchmark. We provide the SVGValidator class that allows you to run StarVector using 1) the HuggingFace generation backend or 2) the VLLM backend. The later is substantially faster thanks to the use of Paged Attention.

    HuggingFace Generation Backend

    Let's start with the evaluation for StarVector-1B and StarVector-8B on SVG-Stack, using the HuggingFace generation backend (StarVectorHFAPIValidator). To override the input arguments, you can add cli args following the yaml file structure.

    # StarVector-1B on SVG-Stack, using the HuggingFace backend 
    python starvector/validation/validate.py \
    config=configs/generation/hf/starvector-1b/im2svg.yaml \
    dataset.dataset_name=starvector/svg-stack
    
    # StarVector-8B on SVG-Stack, using the vanilla HuggingFace generation API
    python starvector/validation/validate.py \
    config=configs/generation/hf/starvector-8b/im2svg.yaml \
    dataset.dataset_name=starvector/svg-stack
    

    vLLM Backend

    For using the vLLM backend (StarVectorVLLMAPIValidator), first install our StarVector fork of VLLM, here.

    git clone https://github.com/starvector/vllm.git
    cd vllm
    pip install -e .
    

    Then, launch the using the vllm config file (it uses StarVectorVLLMValidator):

    # StarVector-1B
    python starvector/validation/validate.py \
    config=configs/generation/vllm/starvector-1b/im2svg.yaml \
    dataset.dataset_name=starvector/svg-stack
    
    # StarVector-8B
    python starvector/validation/validate.py \
    config=configs/generation/vllm/starvector-8b/im2svg.yaml \
    dataset.dataset_name=starvector/svg-stack
    

    We provide evaluation scripts in scripts/eval/*

    StarVector Demo

    The demo provides two options for converting images to SVG code:

    1. HuggingFace generation functionality
    2. VLLM (recommended) - offers faster generation speed

    Option 1: HuggingFace Generation with Gradio Web UI

    We provide a Gradio web UI for you to play with our model.

    Launch a controller
    python -m starvector.serve.controller --host 0.0.0.0 --port 10000
    
    Launch a gradio web server.
    python -m starvector.serve.gradio_web_server --controller http://localhost:10000 --model-list-mode reload --port 7000
    

    You just launched the Gradio web interface. Now, you can open the web interface with the URL printed on the screen. You may notice that there is no model in the model list. Do not worry, as we have not launched any model worker yet. It will be automatically updated when you launch a model worker.

    Launch a model worker

    This is the actual worker that performs the inference on the GPU. Each worker is responsible for a single model specified in --model-path.

    python -m starvector.serve.model_worker --host 0.0.0.0 --controller http://localhost:10000 --port 40000 --worker http://localhost:40000 --model-path joanrodai/starvector-1.4b
    

    Wait until the process finishes loading the model and you see "Uvicorn running on ...". Now, refresh your Gradio web UI, and you will see the model you just launched in the model list.

    You can launch as many workers as you want, and compare between different model checkpoints in the same Gradio interface. Please keep the --controller the same, and modify the --port and --worker to a different port number for each worker.

    vllm serve starvector/starvector-8b-im2svg --chat-template configs/chat-template.jinja --trust-remote-code --port 8001 --max-model-len 16000
    
    python -m starvector.serve.model_worker --host 0.0.0.0 --controller http://localhost:10000 --port <different from 40000, say 40001> --worker http://localhost:<change accordingly, i.e. 40001> --model-path <ckpt2>
    
    Option 2: Launch VLLM
    1. Remember to clone the starvector/vllm fork (it has modifications for starvector).
    git clone https://github.com/starvector/vllm.git
    cd vllm
    pip install -e .
    
    1. Call this to launch the VLLM endpoint
    vllm serve starvector/starvector-1b-im2svg --chat-template configs/chat-template.jinja --trust-remote-code --port 8000 --max-model-len 8192
    
    1. Create the demo for VLLM
    python -m starvector.serve.vllm_api_gradio.controller --host 0.0.0.0 --port 10000
    python -m starvector.serve.vllm_api_gradio.gradio_web_server --controller http://localhost:10000 --model-list-mode reload --port 7000
    python -m starvector.serve.vllm_api_gradio.model_worker --host 0.0.0.0 --controller http://localhost:10000 --port 40000 --worker http://localhost:40000 --model-name starvector/starvector-1b-im2svg --vllm-base-url http://localhost:8000
    
    1. Add more models by serving them with VLLM and calling a new model worker
    vllm serve starvector/starvector-8b-im2svg --chat-template configs/chat-template.jinja --trust-remote-code --port 8001 --max-model-len 16384
    
    python -m starvector.serve.vllm_api_gradio.model_worker --host 0.0.0.0 --controller http://localhost:10000 --port 40001 --worker http://localhost:40001 --model-name starvector/starvector-8b-im2svg --vllm-base-url http://localhost:8001
    

    Citation

    @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}, 
    }
    

    License

    This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.