VectorFusion-pytorch

VectorFusion-pytorch

文本驱动的像素扩散模型到可编辑矢量图形转换工具

VectorFusion-pytorch是一个文本到SVG生成工具,将基于像素的扩散模型抽象化为可导出的矢量图形。支持图标、像素艺术和素描等多种风格,提供详细的安装指南和使用示例。该工具可将光栅图像转换为矢量图,并通过LSDS微调实现高质量的文本引导矢量图形合成。项目提供Docker使用指南和多个案例展示,包括悉尼歌剧院、明朝花瓶、宇航员和吉他等不同主题的矢量图生成过程。此外,VectorFusion-pytorch还支持自定义风格和参数调整,为用户提供灵活的创作空间。

VectorFusion: 通过抽象像素扩散模型实现文本到SVG转换

在这项工作中,作者展示了一个在图像像素表示上训练的文本条件扩散模型可以用来生成可导出SVG的矢量图形。

官方网站: https://vectorfusion.github.io/

<div align="center"> <img src="https://yellow-cdn.veclightyear.com/835a84d5/67b645c8-d67d-41ae-9430-58f7fc00559d.gif" style="width: 100%; height: auto;" alt="VF视频"> <p>VectorFusion渲染过程。(64路径, 72视频, 5千)</p> </div>

更新

  • [2024年1月] 🔥 我们发布了SVGDreamer。SVGDreamer是一种新颖的文本引导矢量图形合成方法。该方法同时考虑了矢量图形的编辑和合成质量。
  • [2023年12月] 🔥 我们发布了PyTorch-SVGRender。Pytorch-SVGRender是用于图像矢量化的最先进可微渲染方法的首选库。
  • [2023年10月] 🔥 我们发布了DiffSketcher代码。一种通过文本提示合成矢量草图的方法。
  • [2023年10月] 🔥 我们复现了VectorFusion代码。

安装

逐步安装

创建新的conda环境:

conda create --name vf python=3.10 conda activate vf

安装pytorch和以下库:

conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.6 -c pytorch -c nvidia pip install omegaconf BeautifulSoup4 pip install shapely pip install opencv-python scikit-image matplotlib visdom wandb pip install triton numba pip install numpy scipy timm scikit-fmm einops pip install accelerate transformers safetensors datasets

安装CLIP:

pip install ftfy regex tqdm pip install git+https://github.com/openai/CLIP.git

安装diffusers:

pip install diffusers==0.20.2

安装xformers(需要python=3.10):

conda install xformers -c xformers

安装diffvg:

git clone https://github.com/BachiLi/diffvg.git cd diffvg git submodule update --init --recursive conda install -y -c anaconda cmake conda install -y -c conda-forge ffmpeg pip install svgwrite svgpathtools cssutils torch-tools python setup.py install

Docker使用

docker run --name vectorfusion --gpus all -it --ipc=host ximingxing/svgrender:v1 /bin/bash

快速开始

案例:悉尼歌剧院

提示词: 悉尼歌剧院。<br/> 风格: 图标<br/> 预览:

<img src="https://yellow-cdn.veclightyear.com/835a84d5/d1e9bb44-0635-4867-b8ed-2ee32f616323.png" style="width: 250px; height: 250px;"><img src="https://yellow-cdn.veclightyear.com/835a84d5/6b2b6428-c742-4c4d-b914-0ea90f6f533f.svg" style="width: 250px; height: 250px;"><img src="https://yellow-cdn.veclightyear.com/835a84d5/fa83d213-8126-452e-b123-5d6a4b17202a.svg" style="width: 250px; height: 250px;">
(a) 使用Stable Diffusion采样的栅格图像(b) 通过LIVE将栅格图像转换为矢量图(c) VectorFusion:通过LSDS微调

LIVE渲染过程:

迭代0迭代500迭代1000迭代1500迭代2500迭代3500
<img src="https://yellow-cdn.veclightyear.com/835a84d5/6df609ac-d4b2-449c-b084-1c8bcd1f1479.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/72ab89af-e3d5-4362-86bf-0f93497eb048.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/88616133-5d28-41be-bbf1-680c6305e90f.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/ec93d8f7-e8c7-4475-8eab-74e208c0a035.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/f7d7ec1f-3168-41e5-b1c6-85606a21e195.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/c800dbb1-7c3e-4231-a9b8-8e0a57903842.svg">

VectorFusion渲染过程:

迭代0迭代100迭代300迭代400迭代700迭代1000
<img src="https://yellow-cdn.veclightyear.com/835a84d5/ab85ecec-f0be-4d03-8f1e-ad67c5b6481c.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/a25ab52e-9391-4309-9ce5-bcd6fb19b60e.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/d431806d-23fc-49f9-95ef-17c1bf613ee8.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/e4187912-b1d8-447d-8b31-93bacf8081d4.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/cd88d41a-d39b-4c57-a797-a5764ec32fcf.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/fa83d213-8126-452e-b123-5d6a4b17202a.svg">

脚本:

python run_painterly_render.py \ -c vectorfusion.yaml \ -pt "悉尼歌剧院。极简平面2D矢量图标。线性颜色。白色背景。ArtStation流行" \ -save_step 50 \ -update "K=6" \ -respath ./workdir/SydneyOperaHouse \ -d 15486 \ --download
  • -c--config:配置文件。
  • -save_step:用于保存结果的步长(调用过于频繁会导致时间更长)。
  • -update:用于编辑配置文件的超参数的工具,因此无需创建新的yaml文件。
  • -pt--prompt:文本提示。
  • -respath--results_path:保存结果的文件夹。
  • -d--seed:随机种子。
  • --download首次运行时自动从huggingface下载模型。

可选:

  • -npt,即 --negative_prompt:负面文本提示。
  • -mv,即 --make_video:制作渲染过程的视频(这将花费更长时间)。
  • -frame_freq,即 --video_frame_freq:保存图像的步数间隔。
  • -framerate,即 --video_frame_rate:控制输出视频的播放速度。

案例:明代花瓶

提示词: 皮革桌面上的明代花瓶照片。<br/> 风格: 图标<br/> 预览:

<img src="https://yellow-cdn.veclightyear.com/835a84d5/27681156-a372-4696-a247-1484cff35b3c.png" style="width: 250px; height: 250px;"><img src="https://yellow-cdn.veclightyear.com/835a84d5/aebcfe59-d1de-44b3-8e4a-708b72659dd9.svg" style="width: 250px; height: 250px;"><img src="https://yellow-cdn.veclightyear.com/835a84d5/fe88de57-e86e-446a-96bf-274efe67146a.svg" style="width: 250px; height: 250px;">
(a) 使用Stable Diffusion采样的栅格图像(b) 通过LIVE将栅格图像转换为矢量图(c) VectorFusion:通过LSDS微调

脚本:

python run_painterly_render.py -c vectorfusion.yaml -pt "皮革桌面上的明代花瓶照片。极简平面2D矢量图标。线性颜色。白色背景。ArtStation流行" -save_step 50 -respath ./workdir/vase -d 683692

案例:宇航员

提示词: 宇航员形象。<br/> 风格: 图标<br/> 预览:

<img src="https://yellow-cdn.veclightyear.com/835a84d5/6970dd0a-01e8-4f5c-995c-7774a354c433.png" style="width: 250px; height: 250px;"><img src="https://yellow-cdn.veclightyear.com/835a84d5/552eec61-bbd6-4799-af92-83de94ad22b4.svg" style="width: 250px; height: 250px;"><img src="https://yellow-cdn.veclightyear.com/835a84d5/9e42ff3b-4e0a-4149-bf05-d3b556381d97.svg" style="width: 250px; height: 250px;">
(a) 使用Stable Diffusion生成的栅格图像样本(b) 通过LIVE将栅格图像转换为矢量图(c) VectorFusion: 通过LSDS进行微调

脚本:

python run_painterly_render.py -c vectorfusion.yaml -pt "宇航员形象。极简平面2D矢量图标。线性配色。白色背景。Artstation热门" -save_step 50 -respath ./workdir/astronaut -d 522178

案例:吉他

提示词: 电吉他 <br/> 风格: 像素艺术 <br/> 预览:

<img src="https://yellow-cdn.veclightyear.com/835a84d5/0f28b561-219b-42d7-8d3f-3fc1b65262ab.png" style="width: 250px; height: 250px;"><img src="https://yellow-cdn.veclightyear.com/835a84d5/a679203d-3874-4a7e-86d7-ce8cd9f140db.svg" style="width: 250px; height: 250px;"><img src="https://yellow-cdn.veclightyear.com/835a84d5/c5630585-0b29-409f-80df-950f6f72698b.svg" style="width: 250px; height: 250px;">
(a) 使用Stable Diffusion生成的栅格图像样本(b) 通过LIVE将栅格图像转换为矢量图(c) VectorFusion: 通过LSDS进行微调

脚本:

python run_painterly_render.py -c vectorfusion.yaml -pt "电吉他。像素艺术。Artstation热门" -save_step 50 -respath ./workdir/guitar -update "style=pixelart" -d 445997

案例:龙

提示词: 一条喷火龙的水彩画。 <br/> 风格: 素描 <br/> 预览:

<img src="https://yellow-cdn.veclightyear.com/835a84d5/fdccecbf-f256-4093-bd77-023b5dfc4cea.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/78a75d27-a21a-4997-a92a-e97b115a9282.svg"><img src="https://yellow-cdn.veclightyear.com/835a84d5/e7469e5d-5e7a-4b08-aaec-974f4c9569f2.svg">
SVG初始化VectorFusion微调500步VectorFusion微调1500步

脚本:

python run_painterly_render.py -c vectorfusion.yaml -pt "一条喷火龙的水彩画。极简2D线条绘画。Artstation热门" -save_step 50 -respath ./workdir/dragon-sketch -update "style=sketch num_segments=5 radius=0.5 sds.num_iter=1500" -d 106764

其他案例

# 素描风格 CUDA_VISIBLE_DEVICES=0 python run_painterly_render.py -c vectorfusion.yaml -pt "一条喷火龙的水彩画。极简2D线条绘画。Artstation热门" -save_step 50 -respath ./workdir/dragon-sketch -update "style=sketch skip_live=True num_paths=32 num_segments=5 radius=0.5 sds.num_iter=1500" -rdbz CUDA_VISIBLE_DEVICES=0 python run_painterly_render.py -c vectorfusion.yaml -pt "一只猫。极简2D线条绘画。Artstation热门" -save_step 50 -respath ./workdir/cat-sketch -update "style=sketch skip_live=True num_paths=32 num_segments=5 radius=0.5 sds.num_iter=1500" -rdbz

更多示例:

更多脚本:

  • 查看 Run.md 获取更多脚本。

致谢

本项目基于以下仓库构建:

我们衷心感谢这些作者的杰出工作。

引用

如果您在研究中使用了这份代码,请引用以下论文:

@inproceedings{jain2023vectorfusion,
  title={Vectorfusion: Text-to-svg by abstracting pixel-based diffusion models},
  author={Jain, Ajay and Xie, Amber and Abbeel, Pieter},
  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  pages={1911--1920},
  year={2023}
}
@inproceedings{xing2023diffsketcher,
  title={DiffSketcher: Text Guided Vector Sketch Synthesis through Latent Diffusion Models},
  author={XiMing Xing and Chuang Wang and Haitao Zhou and Jing Zhang and Qian Yu and Dong Xu},
  booktitle={Thirty-seventh Conference on Neural Information Processing Systems},
  year={2023},
  url={https://openreview.net/forum?id=CY1xatvEQj}
}

许可证

本仓库采用MIT许可证。

编辑推荐精选

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

AI办公办公工具AI工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

下拉加载更多