Given an input image of a scientific or technical figure, the model generates SVG code that reconstructs the figure as a scalable, editable vector graphic.
1import torch
2from PIL import Image
3from transformers import AutoProcessor, AutoModelForImageTextToText
4
5model_name = "XunmeiLiu/VFIG-4B"
6
7processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
8model = AutoModelForImageTextToText.from_pretrained(
9 model_name,
10 torch_dtype=torch.bfloat16,
11 device_map="cuda",
12 trust_remote_code=True,
13)
14model.eval()
15
16def figure_to_svg(image_path: str) -> str:
17 img = Image.open(image_path).convert("RGB")
18
19 messages = [
20 {
21 "role": "user",
22 "content": [
23 {"type": "image"},
24 {"type": "text", "text": "Convert this figure into valid SVG code."},
25 ],
26 }
27 ]
28
29 chat_input = processor.tokenizer.apply_chat_template(
30 messages, tokenize=False, add_generation_prompt=True
31 )
32 inputs = processor(text=[chat_input], images=[img], return_tensors="pt").to("cuda")
33
34 with torch.no_grad():
35 output_ids = model.generate(**inputs, max_new_tokens=8192, do_sample=False)
36
37 decoded = processor.tokenizer.decode(output_ids[0], skip_special_tokens=True)
38
39 if "<svg" in decoded:
40 decoded = decoded[decoded.find("<svg"):]
41 if "</svg>" in decoded:
42 decoded = decoded[: decoded.find("</svg>") + len("</svg>")]
43 return decoded.strip()
44
45# Download the example image
46import urllib.request
47urllib.request.urlretrieve(
48 "https://huggingface.co/XunmeiLiu/VFIG-4B/resolve/main/simple_diagram.png",
49 "simple_diagram.png"
50)
51
52svg_code = figure_to_svg("simple_diagram.png")
53print(svg_code)
1@misc{he2026vfigvectorizingcomplexfigures,
2 title={VFIG: Vectorizing Complex Figures in SVG with Vision-Language Models},
3 author={Qijia He and Xunmei Liu and Hammaad Memon and Ziang Li and Zixian Ma and Jaemin Cho and Jason Ren and Daniel S Weld and Ranjay Krishna},
4 year={2026},
5 eprint={2603.24575},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2603.24575},
9}