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

效果展示:

相关推荐
盼小辉丶11 分钟前
深度解析强化学习:原理、算法与实战
深度学习·强化学习
硅谷秋水18 分钟前
OpenDriveVLA:通过大型视觉-语言-动作模型实现端到端自动驾驶
人工智能·机器学习·计算机视觉·语言模型·机器人·自动驾驶
蚝油菜花22 分钟前
【内附榜单】评估AI大模型的代码修复能力!Multi-SWE-bench:字节开源代码修复能力评估基准,覆盖7大主流编程语言
人工智能·开源
北极的树24 分钟前
Vibe coding 最后一公里: 打造一套通用的AI任务拆分和管理系统
人工智能
蚝油菜花24 分钟前
1天消化完Spring全家桶文档!DevDocs:一键深度解析开发文档,自动发现子URL并建立图谱
人工智能·开源
蚝油菜花25 分钟前
让AI绘画进入「指哪画哪」的精准时代!EasyControl:Tiamat AI 联合上海科大开源图像生成控制框架
人工智能·开源
飞哥数智坊27 分钟前
ADK开源:谷歌持续发力Agent,请快速跟进
人工智能·trae
声网27 分钟前
Orpheus 语音模型支持中文预训练和微调,模拟细微语音特征;谷歌版 MCP 来了,A2A 协议让不同厂商 Agent 协作
人工智能
zq.xidian37 分钟前
【开发工具】科研开发中的主流AI工具整理及如何使用GPT润色英文论文
人工智能·gpt
Tezign_space39 分钟前
atypica.AI:用「语言模型」为「主观世界」建模
人工智能·语言模型·aigc·内容科技