赞
踩
首先下载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 .
安装完成xformers之后总是报错,因此就没安装,反正也可以跑。
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
如果用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
代码github地址:
https://github.com/Stability-AI/stablediffusion.git
xformers github地址:
https://github.com/facebookresearch/xformers.git
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。