复现: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

效果展示:

相关推荐
秋91 天前
从 Python 后端工程师转型 AI Engineer(AI 工程化)的完整补课清单(2026实战版)
开发语言·人工智能·python
啦啦啦_99991 天前
5. 迁移学习
人工智能·机器学习·迁移学习
A.说学逗唱的Coke1 天前
【AI·Coding】TDD × SDD × AI Coding:从“测试驱动“到“规范驱动“的智能协作实践
人工智能·驱动开发·tdd
云烟成雨TD1 天前
Spring AI Alibaba 1.x 系列【78】沙箱(Sandbox)
java·人工智能·spring
tq10861 天前
基于SLIP的防幻觉的指南
人工智能
甲维斯1 天前
Kimi版超级玛丽效果“惊人”,配额不足5厘米!
前端·人工智能
console.log('npc')1 天前
AI前端工程与生成式UI学习路线
前端·人工智能·ui
秋91 天前
3年经验Python后端转AI Engineer:3个月实战转型计划(2026版)
开发语言·人工智能·python
圣殿骑士-Khtangc1 天前
GPT-5.5 技术深度解析与企业级生产落地实战:从幻觉率下降到百万Token工程化
人工智能·gpt
2601_961963381 天前
技术解剖:哈希值、区块链与CA认证如何守护电子合同安全?
网络·人工智能·安全·区块链·智能合约·政务