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

效果展示:

相关推荐
算家计算几秒前
4 位量化 + FP8 混合精度:ERNIE-4.5-0.3B-Paddle本地部署,重新定义端侧推理效率
人工智能·开源
晓13133 分钟前
OpenCV篇——项目(二)OCR文档扫描
人工智能·python·opencv·pycharm·ocr
小白狮ww6 分钟前
VASP 教程:VASP 机器学习力场微调
人工智能·深度学习·机器学习
AIGC包拥它6 分钟前
提示技术系列——链式提示
人工智能·python·langchain·prompt
jndingxin13 分钟前
OpenCV CUDA模块设备层-----在GPU 上高效地执行两个 uint 类型值的最大值比较函数vmax2()
人工智能·opencv·计算机视觉
阿水实证通20 分钟前
Stata如何做机器学习?——SHAP解释框架下的足球运动员价值驱动因素识别:基于H2O集成学习模型
人工智能·机器学习·集成学习
新智元23 分钟前
图灵奖大佬向 97 年小孩哥汇报?小扎 1 亿年薪买新贵,老将痛诉熬夜捡 GPU!
人工智能·openai
真智AI24 分钟前
AI智能体时代来临:数据分析的变革与自动化之路
人工智能·数据分析·自动化
非ban必选26 分钟前
spring-ai-alibaba官方 Playground 示例
java·人工智能·spring
新智元34 分钟前
刚刚,Ilya 官宣出任 SSI CEO!送走「叛徒」联创,豪言不缺 GPU
人工智能·openai