Image-Text-to-Text
Transformers
Safetensors
English
qwen2_5_vl
svg
xml
image-to-svg
structured-images
diagrams
vector-graphics
qwen2.5-vl
grpo
reinforcement-learning
multimodal
conversational
text-generation-inference
Instructions to use Pengyu965/Back2Struct-Image2SVG-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Pengyu965/Back2Struct-Image2SVG-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Pengyu965/Back2Struct-Image2SVG-7B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Pengyu965/Back2Struct-Image2SVG-7B") model = AutoModelForMultimodalLM.from_pretrained("Pengyu965/Back2Struct-Image2SVG-7B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Pengyu965/Back2Struct-Image2SVG-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Pengyu965/Back2Struct-Image2SVG-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Pengyu965/Back2Struct-Image2SVG-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Pengyu965/Back2Struct-Image2SVG-7B
- SGLang
How to use Pengyu965/Back2Struct-Image2SVG-7B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Pengyu965/Back2Struct-Image2SVG-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Pengyu965/Back2Struct-Image2SVG-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Pengyu965/Back2Struct-Image2SVG-7B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Pengyu965/Back2Struct-Image2SVG-7B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Pengyu965/Back2Struct-Image2SVG-7B with Docker Model Runner:
docker model run hf.co/Pengyu965/Back2Struct-Image2SVG-7B
Add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: Qwen/Qwen2.5-VL-7B-Instruct
|
| 4 |
+
pipeline_tag: image-text-to-text
|
| 5 |
+
library_name: transformers
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
datasets:
|
| 9 |
+
- Pengyu965/StructHub
|
| 10 |
+
tags:
|
| 11 |
+
- svg
|
| 12 |
+
- xml
|
| 13 |
+
- image-to-svg
|
| 14 |
+
- structured-images
|
| 15 |
+
- diagrams
|
| 16 |
+
- vector-graphics
|
| 17 |
+
- qwen2.5-vl
|
| 18 |
+
- grpo
|
| 19 |
+
- reinforcement-learning
|
| 20 |
+
- multimodal
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# Back2Struct-Image2SVG-7B
|
| 24 |
+
|
| 25 |
+
**Back2Struct** recovers **editable, object-level SVG / XML code** from images of structured
|
| 26 |
+
graphics (diagrams, charts, flowcharts, architecture figures, UML, schemas). Instead of
|
| 27 |
+
low-level pixel vectorization, it predicts vector primitives that explicitly encode text,
|
| 28 |
+
shapes, topology, and layout β so the output can be imported into tools like PowerPoint and
|
| 29 |
+
edited, restyled, and reused while preserving structural fidelity.
|
| 30 |
+
|
| 31 |
+
This checkpoint is the reinforcement-learning model (**GRPO checkpoint-2200**), fine-tuned
|
| 32 |
+
from `Qwen/Qwen2.5-VL-7B-Instruct`.
|
| 33 |
+
|
| 34 |
+
- π Paper: *Back2Struct: Making Structured Images Editable Again*
|
| 35 |
+
- π Project page: https://pengyu965.github.io/Back2Struct.github.io/
|
| 36 |
+
- π Dataset: [`Pengyu965/StructHub`](https://huggingface.co/datasets/Pengyu965/StructHub)
|
| 37 |
+
|
| 38 |
+
## Training
|
| 39 |
+
|
| 40 |
+
| | |
|
| 41 |
+
|---|---|
|
| 42 |
+
| **Base model** | Qwen/Qwen2.5-VL-7B-Instruct (7B) |
|
| 43 |
+
| **Stage 1 β SFT** | Supervised fine-tuning on StructHub imageβSVG pairs (β€ 8,192 tokens) |
|
| 44 |
+
| **Stage 2 β GRPO** | Group-Relative Policy Optimization (TRL), checkpoint **2200** |
|
| 45 |
+
| **Reward** | Composite, render-gated: syntactic validity (must render) Γ perceptual fidelity β a baseline-subtracted DINOv2 similarity between the rendered prediction and the target image; encourages compilability, length consistency, and structural/semantic faithfulness |
|
| 46 |
+
| **Max output length** | 8,192 tokens |
|
| 47 |
+
| **Adapter** | LoRA (r=64, Ξ±=128), merged into the released weights |
|
| 48 |
+
|
| 49 |
+
## Results
|
| 50 |
+
|
| 51 |
+
**StructHub benchmark (1,000 samples), render-gated evaluation** β a non-rendering prediction
|
| 52 |
+
scores 0 on DINO/SSIM/GPT and 1 on LPIPS. SR = render success (%); GPT = 0β100 GPTScore.
|
| 53 |
+
|
| 54 |
+
| Model | SR β | DINO β | LPIPS β | SSIM β | GPT β |
|
| 55 |
+
|-------|-----:|-------:|--------:|-------:|------:|
|
| 56 |
+
| Qwen3-VL-30B-A3B | 18.8 | 0.1566 | 0.9067 | 0.1201 | 13.29 |
|
| 57 |
+
| StarVector-8B | 31.4 | 0.2694 | 0.7936 | 0.2170 | 21.05 |
|
| 58 |
+
| Qwen2.5-VL-7B (base) | 52.3 | 0.3527 | 0.7834 | 0.3276 | 27.56 |
|
| 59 |
+
| Qwen2.5-VL-7B (SFT) | 42.8 | 0.3715 | 0.7403 | 0.2891 | 33.49 |
|
| 60 |
+
| **Back2Struct (RL, this model)** | **71.5** | **0.5622** | **0.6473** | **0.4966** | **51.85** |
|
| 61 |
+
|
| 62 |
+
**On successfully compiled outputs**, the 7B model matches or beats frontier closed models:
|
| 63 |
+
|
| 64 |
+
| Model | DINO β | LPIPS β | SSIM β | GPT β |
|
| 65 |
+
|-------|-------:|--------:|-------:|------:|
|
| 66 |
+
| Gemini-2.5-Pro | **0.8855** | 0.4648 | 0.6532 | 77.95 |
|
| 67 |
+
| GPT-5 | 0.8852 | 0.4350 | 0.6573 | 77.21 |
|
| 68 |
+
| **Back2Struct (7B)** | 0.8697 | **0.3896** | **0.6738** | **78.63** |
|
| 69 |
+
|
| 70 |
+
## Usage
|
| 71 |
+
|
| 72 |
+
```python
|
| 73 |
+
import torch
|
| 74 |
+
from transformers import Qwen2_5_VLForConditionalGeneration, AutoProcessor
|
| 75 |
+
from qwen_vl_utils import process_vision_info
|
| 76 |
+
|
| 77 |
+
model_id = "Pengyu965/Back2Struct-Image2SVG-7B"
|
| 78 |
+
model = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 79 |
+
model_id, torch_dtype=torch.bfloat16, device_map="auto")
|
| 80 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 81 |
+
|
| 82 |
+
messages = [{
|
| 83 |
+
"role": "user",
|
| 84 |
+
"content": [
|
| 85 |
+
{"type": "image", "image": "diagram.png"},
|
| 86 |
+
{"type": "text", "text": "Convert this structured image into editable SVG/XML code."},
|
| 87 |
+
],
|
| 88 |
+
}]
|
| 89 |
+
|
| 90 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 91 |
+
image_inputs, video_inputs = process_vision_info(messages)
|
| 92 |
+
inputs = processor(text=[text], images=image_inputs, videos=video_inputs,
|
| 93 |
+
padding=True, return_tensors="pt").to(model.device)
|
| 94 |
+
|
| 95 |
+
generated = model.generate(**inputs, max_new_tokens=8192, do_sample=False)
|
| 96 |
+
svg = processor.batch_decode(
|
| 97 |
+
generated[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)[0]
|
| 98 |
+
print(svg) # render with cairosvg or import into PowerPoint
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
## Intended use & limitations
|
| 102 |
+
|
| 103 |
+
- **Intended use:** recovering editable vector code from images of *structured* graphics.
|
| 104 |
+
- **Not for:** photographic / natural-image vectorization.
|
| 105 |
+
- **Limitations:** built on a general (non-code-specialized) VLM backbone; outputs are capped
|
| 106 |
+
at 8,192 tokens, which bounds the complexity of very large diagrams; very long / dense
|
| 107 |
+
graphics (the *hard* tier) remain the main failure mode (render reliability).
|
| 108 |
+
|
| 109 |
+
## Citation
|
| 110 |
+
|
| 111 |
+
```bibtex
|
| 112 |
+
@article{yan2026back2struct,
|
| 113 |
+
title = {Back2Struct: Making Structured Images Editable Again},
|
| 114 |
+
author = {Yan, Pengyu and Wu, Yixin and Tian, Yunjie and Doermann, David},
|
| 115 |
+
year = {2026},
|
| 116 |
+
note = {Preprint}
|
| 117 |
+
}
|
| 118 |
+
```
|