LayerTracer
April 1, 2025 · View on GitHub
LayerTracer: Cognitive-Aligned Layered SVG Synthesis via Diffusion Transformer
Yiren Song,
Danze Chen,
and
Mike Zheng Shou
Show Lab, National University of Singapore
Installation
1. Environment setup
git clone https://github.com/showlab/LayerTracer.git
cd LayerTracer
conda create -n layertracer python=3.11.10
conda activate layertracer
2. Requirements installation
pip install --upgrade -r requirements.txt
LoRa models
You can download the trained checkpoints of LoRA for text2sequence inference. Below are the details of available models:
| Model | Description | Resolution |
|---|---|---|
| flux_lora_icon_blackline | This model is used to generate nine grid icon images with black lines. | 768,768 |
| flux_lora_emoji | This model is used to generate four grid emoji and icon images. | 1024,1024 |
Inference
1. Text 2 Sequence
According to the actual situation, replace all model paths, file paths, and parameters in scripts/text2sequence.sh.
chmod +x scripts/text2sequence.sh
scripts/text2sequence.sh
NOTICE
When generating 9-grid images using prompts, please modify your prompt according to the examples provided below to avoid generating irrelevant content. Add this prefix to your prompt:
# nine-grid icon
sks, This is a nine square grid image that describes the process of creating SVG icon images, ...
# or
sks, a set of nine icons, each representing ...
# four-grid emoji
sks, This is a four square grid image that describes the process of creating SVG emoji images, ...
2. Image 2 Sequence
2.1 Merge LoRA to flux.1
Use our scripts/lora_merge.sh template script to merge the LoRA (flux_lora_icon_blackline and flux_lora_emoji) to flux.1 checkpoints for further recraft training. Note that the merged model may take up around 50GB of your memory space.
chmod +x scripts/lora_merge.sh
scripts/lora_merge.sh
2.2 Recraft model
According to the actual situation, replace all model paths, file paths, and parameters in scripts/image2sequence.sh.
The icon_lora_weights is a Recraft model used for generating 9-grid black line icon images. Simply replace the corresponding paths in scripts/image2sequence.sh to use it.
chmod +x scripts/image2sequence.sh
scripts/image2sequence.sh
QuickStart
9grid Sequence(blackline) to SVG
python layertracer_icon_9grid.py --input input/icon.png --output output/
--input: Input image path.--output: Output directory.--colormode: choices=['color', 'binary'], Color mode for SVG conversion.--mode: choices=['spline', 'polygon', 'none'], Tracing mode for SVG conversion.--filter_speckle: Speckle filter threshold.--color_precision: Color precision for SVG conversion.--corner_threshold: Corner detection threshold.--length_threshold: Length threshold for path simplification, in [3.5, 10].--splice_threshold: Splice threshold for path merging.--path_precision: Path precision for SVG conversion.
4grid Sequence to SVG
You can customize the parameters, just like the above process:
python layertracer_emoji_4grid.py --input input/emoji.png --output output/
Dataset
Citation
@inproceedings{Song2025LayerTracerCL,
title={LayerTracer: Cognitive-Aligned Layered SVG Synthesis via Diffusion Transformer},
author={Yiren Song and Danze Chen and Mike Zheng Shou},
year={2025},
url={https://api.semanticscholar.org/CorpusID:276094351}
}