当前位置:   article > 正文

stablediffusion代码实践

stablediffusion代码实践

1.安装环境

首先下载stablediffusion代码

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

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

conda env create -f environment.yaml
conda activate ldm
  • 1
  • 2

由于我的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 .
  • 1
  • 2
  • 3

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模型的权重
  • 1
  • 2

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  
  • 1

如果用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
  • 1

如果出现错误,要把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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/478678
推荐阅读
相关标签
  

闽ICP备14008679号