推荐:write_own_pipeline.ipynb - Colab (google.com)
基本管道
一直显示NVIDIA有问题,所以就把.to("cuda")去掉了,使用Colab运行的,代码如下:
from diffusers import DDPMPipeline
ddpm = DDPMPipeline.from_pretrained("google/ddpm-cat-256", use_safetensors=True)
image = ddpm(num_inference_steps=25).images[0]
image
效果如下(有一点点诡异,再配一张好看的图QAQ,毕竟是鼻祖ddpm嘛~)
手撕管道
加载模型和调度程序
from diffusers import DDPMScheduler, UNet2DModel
scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
model = UNet2DModel.from_pretrained("google/ddpm-cat-256", use_safetensors=True).to("cuda")
话说,这个DDPMScheduler和UnetDModel是干什么的,明天继续~