Baidu Open-Sources Unlimited-SVG to Turn Any Photo Into Editable Vector Code
Baidu open-sources a 3.3B mixture-of-experts model that redraws any image as a structured, editable SVG using just 0.5B active parameters.
Takeaways
- Baidu open-sourced Unlimited-SVG, an MIT-licensed image-to-SVG model built on DeepSeek-OCR.
- 3.34B total parameters with ~0.5B active per token via a 64-expert MoE decoder (6 routed per token).
- Compresses 2048x2048 images to 1024 vision tokens, sustains generation past 10K output tokens in real time.
- Produces layered, editable SVG with real text elements, not pixel-traced bezier soup.
- Runs locally on a 12 GB BF16 NVIDIA GPU; ships Transformers and vLLM inference paths.
- Available on Hugging Face with a hosted ZeroGPU demo.
Baidu’s ERNIE multimodal team has released Unlimited-SVG, an MIT-licensed model that generates SVG code from photos, screenshots, diagrams, and blueprints. It can emit paths, groups, text elements, colors, and coordinates, producing editable structure that conventional contour tracers often lose.
The weights are available on the model page, and a hosted demo provides browser-based testing. The project targets local deployment on a BF16-capable NVIDIA GPU, with 12 GB of VRAM as the practical minimum.
Why 10,000 tokens change the design
Complex images can require more than 10,000 generated tokens because every path, coordinate, style, group, and text element becomes part of the output sequence. Dense models apply their full feed-forward network to each token, making long SVG generation expensive.
The model card describes a 3.34-billion-parameter mixture-of-experts model built from DeepSeek-OCR’s vision encoder and a DeepSeek-V2 MoE decoder. About 0.5 billion parameters activate for each token.
| Component | Specification |
|---|---|
| Base architecture | DeepSeek-OCR with DeepEncoder and a DeepSeek-V2 MoE decoder |
| Experts | 64 routed experts, 6 active per token, plus 2 shared experts |
| Weights | One BF16 safetensors file, approximately 6.7 GB or 6.21 GiB |
| Image input | 2048 × 2048 canvas compressed into 1,024 visual tokens |
| Context window | 32,768 tokens, including the visual prefix and generated sequence |
| Memory estimate | 6.21 GiB for weights and up to 1.78 GiB for the cache, before activations and runtime overhead |
Each input is padded to a square canvas while preserving its aspect ratio, then encoded into a relatively small visual prefix. The compression is designed to retain fine text, thin strokes, and spatial coordinates without filling the context window before generation begins.
Sparse routing reduces the feed-forward work performed for each output token. Attention still processes the growing sequence, and the key-value cache still consumes memory, so generation slows as the SVG expands. The architecture nevertheless makes long output cheaper than an equivalently sized dense decoder.
From contours to object structure
Classical tools such as Potrace and VTracer derive vector contours from raster boundaries. Unlimited-SVG generates the document as code, allowing it to represent objects, spatial relationships, colors, text, and drawing order through SVG elements.
The model can produce separate paths and groups, along with real <text> elements when it recognizes text correctly. Those structures are easier to inspect and modify in tools such as Illustrator and Figma than a large collection of paths fitted to anti-aliased edges.
Baidu lists logos, icons, charts, page layouts, floor plans, architectural drawings, and rasterized CAD material among the intended inputs. Editability depends on generation quality: text may be misread, shapes may be merged, and visual layers do not guarantee meaningful names or grouping.
Two routes to local inference
The repository provides a Transformers inference script and a vLLM server configuration. Both use a 2048 × 2048 padded input and run greedy decoding by default. Local execution requires Linux and a BF16-capable NVIDIA GPU.
The project recommends different sampling ranges according to the source material:
| Input type | Temperature | Goal |
|---|---|---|
| CAD drawings, diagrams, charts, and geometry-sensitive images | 0 to 0.3 | Preserve coordinates, labels, and repeated structure |
| Natural scenes and photographs | 0.5 to 0.8 | Reduce repetitive stroke loops by allowing more variation |
Temperature affects output only when sampling is enabled. Greedy decoding remains the more deterministic choice for layouts in which coordinates and text must stay stable.
The core Transformers inference call follows this pattern:
import re
raw = model.infer(
tokenizer,
prompt="<image> SVG:",
image_file=prepared,
output_path=directory,
base_size=2048,
image_size=2048,
crop_mode=False,
eval_mode=True,
)
match = re.search(r"<svg\b.*?</svg>", raw, re.DOTALL)
if match is None:
raise ValueError("The response contains no complete SVG")
svg = match.group(0)
The extraction guard matters because a generation can end before the closing </svg> tag. Production pipelines should also parse the result as XML and reject malformed documents before storing or rendering them.
The vLLM implementation patches the DeepSeek-OCR processor to disable image tiling and exposes an OpenAI-compatible chat endpoint. That route suits batched or service-based workloads, while the Transformers script provides a simpler path for experiments and offline conversion.
Jobs suited to SVG output
- Extracting design assets from raster mockups and screenshots
- Converting legacy diagrams, floor plans, and technical drawings into editable vectors
- Refactoring icon and logo collections into separate SVG elements
- Representing document layouts as compact, searchable intermediate data
- Building self-hosted alternatives to per-call vision-model APIs
The model consumes raster images, so PDF pages and native CAD views need rendering before inference unless an application supplies that preprocessing. Its output contains visual SVG geometry rather than parametric CAD constraints, making dimension and label validation necessary for engineering workflows.
Before generated SVG reaches production
- Benchmark gap: At release, Baidu said a technical report was forthcoming and had not published comparisons with proprietary vision-language models or established tracing tools.
- Unknown demo performance: The hosted demo does not disclose its hardware, so its latency does not establish local generation speed.
- Output reliability: Generated files can contain incomplete XML, duplicated paths, inaccurate text, or incorrect coordinates. Automated validation and visual review remain necessary.
- Content sensitivity: The separate temperature guidance for geometric and photographic inputs indicates that one decoding configuration will not suit every image type.
- Browser safety: Applications should sanitize SVG before serving it to users, removing scripts, event handlers, external URLs, and elements such as
<foreignObject>.