复现:latent diffusion(LDM)stable diffusion

复现LDM 已解决所有报错

下载项目

https://github.com/CompVis/latent-diffusion

然后运行环境配置:

复制代码
conda env create -f environment.yaml
conda activate ldm

下载预先训练的权重:

python 复制代码
下载官方权重文件:
mkdir -p models/ldm/text2img-large/
wget -O models/ldm/text2img-large/model.ckpt https://ommer-lab.com/files/latent-diffusion/nitro/txt2img-f8-large/model.ckpt

# 下载modelscope的权重文件:
# pip install modelscope
# modelscope download --model AI-ModelScope/stable-diffusion-v1-5 v1-5-pruned-emaonly.ckpt --local_dir ./models/ldm/stable-diffusion-v1-5
# 链接起来:
# ln -s /root/netdisk/latent-diffusion-main/models/ldm/stable-diffusion-v1-5/v1-5-pruned-emaonly.ckpt models/ldm/stable-diffusion-v1/model.ckpt
复制代码
# 1. 克隆 taming-transformers 仓库
git clone https://github.com/CompVis/taming-transformers.git
cd taming-transformers
安装 taming 模块
pip install .
返回项目根目录
cd /root/netdisk/latent-diffusion-main
直接引用taming包需要将下载的包放到固定的环境目录下:
cp -r /root/netdisk/latent-diffusion-main/taming-transformers /root/.pyenv/versions/3.8.0/lib/python3.8/site-packages
python -c "import taming-transformers; print(my_package.__file__)"

手动下载bert-base-uncased:https://huggingface.co/google-bert/bert-base-uncased/tree/main

修改代码:

复制代码
from transformers import BertTokenizerFast  # TODO: add to reuquirements
        # 从本地路径加载分词器
        self.tokenizer = BertTokenizerFast.from_pretrained("./bert-base-uncased")

运行采样生成:

复制代码
python scripts/txt2img.py --prompt "a virus monster is playing guitar, oil on canvas" --ddim_eta 0.0 --n_samples 4 --n_iter 4 --scale 5.0  --ddim_steps 50

python scripts/txt2img.py --prompt "Handsome man and beautiful woman walking in the rain, oil on canvas" --ddim_eta 0.0 --n_samples 4 --n_iter 4 --scale 5.0  --ddim_steps 50

效果展示:

相关推荐
gooxi_hui几秒前
海量存力,智驭未来丨国鑫4U60盘位高密度存储服务器SL401-G4重磅上市
运维·服务器·人工智能
太子釢1 分钟前
Claude Code 工具调用机制详解
人工智能
ksueh8 分钟前
AI写小说接入文心一言教程:千帆API+向量记忆系统实现百万字长篇智能创作
人工智能·ai助手
不焦躁的程序员11 分钟前
程序员该补获客能力了
人工智能·程序员
AI科技星13 分钟前
基于32维Cayley_Dickson超复数的全域拓扑统一场论——反重力、真空自持供能、维度瞬移与星际宇宙脑秩序体系
人工智能·学习·算法·机器学习·数据挖掘
星马梦缘17 分钟前
机器学习与模式识别 第十四章 神经网络中的反向传播 模拟卷及答案
人工智能·神经网络·机器学习·微分·反向传播
吴bug19 分钟前
认识 Open-ACE — AI 编程智能体的工作空间
人工智能·ai·ai编程
ksueh24 分钟前
AI写小说工具哪个好用?9款AI工具使用体验(2026年横评)
人工智能·ai写作
Bode_200225 分钟前
Codex 的安装与使用指南
人工智能
“码”力全开27 分钟前
ONVIF摄像头接入项目实战记录
人工智能·算法·边缘计算