🚀 无向量量化的自回归图像生成
本模型(MAR)引入了一种新颖的自回归图像生成方法,无需进行向量量化。该模型不依赖离散令牌,而是在连续值空间中使用扩散过程对每个令牌的概率分布进行建模。通过采用扩散损失函数,模型在实现高效高质量图像生成的同时,还能受益于自回归序列建模的速度优势。这种方法简化了生成过程,使其不仅适用于图像合成,还能应用于更广泛的连续值领域。它基于这篇论文。
🚀 快速开始
你可以通过Hugging Face的DiffusionPipeline
轻松加载该模型,并可选择自定义各种参数,如模型类型、步数和类别标签。
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained("jadechoghari/mar", trust_remote_code=True, custom_pipeline="jadechoghari/mar")
generated_image = pipeline(
model_type="mar_huge",
seed=42,
num_ar_steps=64,
class_labels=[207, 360, 388],
cfg_scale=4,
output_dir="./images",
cfg_schedule = "constant",
)
generated_image.show()
此代码加载模型,配置其进行图像生成,并将输出保存到指定目录。
我们以safetensors
格式提供了三个预训练的MAR模型:
mar-base.safetensors
mar-large.safetensors
mar-huge.safetensors
这是论文无向量量化的自回归图像生成在Hugging Face Diffusers/GPU上的实现。
官方的PyTorch实现发布在这个仓库。
@article{li2024autoregressive,
title={Autoregressive Image Generation without Vector Quantization},
author={Li, Tianhong and Tian, Yonglong and Li, He and Deng, Mingyang and He, Kaiming},
journal={arXiv preprint arXiv:2406.11838},
year={2024}
}
✨ 主要特性
- 引入新颖的自回归图像生成方法,无需向量量化。
- 在连续值空间中使用扩散过程对每个令牌的概率分布进行建模。
- 采用扩散损失函数,实现高效高质量图像生成,同时受益于自回归序列建模的速度优势。
- 简化生成过程,适用于更广泛的连续值领域。
💻 使用示例
基础用法
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained("jadechoghari/mar", trust_remote_code=True, custom_pipeline="jadechoghari/mar")
generated_image = pipeline(
model_type="mar_huge",
seed=42,
num_ar_steps=64,
class_labels=[207, 360, 388],
cfg_scale=4,
output_dir="./images",
cfg_schedule = "constant",
)
generated_image.show()
高级用法
你可以根据实际需求进一步调整模型参数,以实现不同的图像生成效果。例如,调整num_ar_steps
来改变自回归步数,或者调整cfg_scale
来改变分类器自由引导比例。
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained("jadechoghari/mar", trust_remote_code=True, custom_pipeline="jadechoghari/mar")
generated_image = pipeline(
model_type="mar_large",
seed=123,
num_ar_steps=128,
class_labels=[100, 200, 300],
cfg_scale=6,
output_dir="./new_images",
cfg_schedule = "linear",
)
generated_image.show()
📄 许可证
本项目采用MIT许可证。