stablediffusion代码实践

1.安装环境

首先下载stablediffusion代码

git clone https://github.com/Stability-AI/stablediffusion.git
cd stablediffusion

官网给出的安装环境的提示
官网给出的是更新latent diffusion环境的命令,但是因为我之前没有安装过latent diffusion的环境,于是这里先安装环境:

conda env create -f environment.yaml
conda activate ldm

由于我的CUDA版本是12.0, 官网给出的torch版本太低,与我的CUDA版本不兼容,所以修改了一下我的pytorch安装的命令。

conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
pip install transformers==4.19.2 diffusers invisible-watermark
pip install -e .

2. 安装xformers

安装完成xformers之后总是报错,因此就没安装,反正也可以跑。

3. 下载权重

wget https://huggingface.co/stabilityai/stable-diffusion-2-1 		#SD2.1-v模型的权重
wget https://huggingface.co/stabilityai/stable-diffusion-2-1-base		#SD2.1-base模型的权重

Stable Diffusion 2.1-v的分辨率是768768,Stable Diffusion 2.1-base模型的分辨率是512512

4. 运行示例

如果用SD2.1-v model采样,运行代码为:

python scripts/txt2img.py --prompt "a professional photograph of an astronaut riding a horse" --ckpt <path/to/768model.ckpt/> --config configs/stable-diffusion/v2-inference-v.yaml --H 768 --W 768 --precision full  

如果用base model采样,运行代码为:

python scripts/txt2img.py --prompt "a professional photograph of an astronaut riding a horse" --ckpt <path/to/model.ckpt/> --config <path/to/config.yaml/>  --precision full

如果出现错误,要把inference.yaml文件中的use_fp16: True改成use_fp16: False

5.参考

代码github地址:

https://github.com/Stability-AI/stablediffusion.git

xformers github地址:

https://github.com/facebookresearch/xformers.git

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值