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

效果展示:

相关推荐
Sui_Network22 分钟前
备受期待的 POP 射击游戏 XOCIETY 正式在 Epic Games Store 开启体验
人工智能·游戏·rpc·区块链·量子计算·graphql
漫长的~以后35 分钟前
GPT-5.2深度拆解:多档位自适应架构如何重塑AI推理效率
人工智能·gpt·架构
爱笑的眼睛1140 分钟前
自动机器学习组件的深度解析:超越AutoML框架的底层架构
java·人工智能·python·ai
LCG米43 分钟前
嵌入式Python工业环境监测实战:MicroPython读取多传感器数据
开发语言·人工智能·python
努力的BigJiang1 小时前
Cube-slam复现及报错解决
人工智能
ComputerInBook1 小时前
代数基本概念理解——特征向量和特征值
人工智能·算法·机器学习·线性变换·特征值·特征向量
漫长的~以后2 小时前
Edge TPU LiteRT V2拆解:1GB内存设备也能流畅跑AI的底层逻辑
前端·人工智能·edge
星火10242 小时前
“重生”之我用 Solo 写了一盘中国象棋
人工智能·ai编程
祝余Eleanor2 小时前
Day37 模型可视化与推理
人工智能·python·深度学习
是Dream呀2 小时前
【openFuyao】openFuyao社区AI推理加速组件技术解析与实践
人工智能·架构·openfuyao