Stable diffusion环境部署搭建

1、安装Nvidia驱动、cuda版本等

2、安装anaconda环境

3、安装git

#git工具的安装参考下面命令 
apt-get update -y a
pt-get upgrade -y 
apt install git

4、下载源码和模型参数文件

#1、下载源码
git clone https://github.com/CompVis/stable-diffusion.git
#2、下载模型参数文件,以下示例为v1.4版本,大约7GB
wget https://xujianhua-bj.tos-cn-beijing.volces.com/sd-v1-4-full-ema.ckpt
#3、设置模型参数存放位置
#git下来的stable-diffusion文件夹路径中创建stable-diffusion-v1目录
mkdir -p /root/stable-diffusion/models/ldm/stable-diffusion-v1/
#将下载的模型参数文件改名为 model.ckpt 并放在 stable-diffusion-v1 目录下
ln -s /root/sd-v1-4-full-ema.ckpt /root/stable-diffusion/models/ldm/stable-diffusion-v1/model.ckpt

5、Anaconda创建 ldm 虚拟环境

#切换清华源,便于后续生成环境,下载python包 
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

//注意:火山引擎FT的只开github的加速,不开http/https代理。因为设置http/https代理, 执行conda env create -f environment.yaml会报错。

#进入之前的源码解压目录
cd stable-diffusion
conda env create -f environment.yaml
conda activate ldm
#environment.yaml的内容
name: ldm
channels:
  - pytorch
  - defaults
dependencies:
  - python=3.8.5
  - pip=20.3
  - cudatoolkit=11.3
  - pytorch=1.11.0
  - torchvision=0.12.0
  - numpy=1.19.2
  - pip:
    - albumentations==0.4.3
    - diffusers
    - opencv-python==4.1.2.30
    - pudb==2019.2
    - invisible-watermark
    - imageio==2.9.0
    - imageio-ffmpeg==0.4.2
    - pytorch-lightning==1.4.2
    - omegaconf==2.1.1
    - test-tube>=0.7.5
    - streamlit>=0.73.1
    - einops==0.3.0
    - torch-fidelity==0.3.0
    - transformers==4.19.2
    - torchmetrics==0.6.0
    - kornia==0.6
    - -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
    - -e git+https://github.com/openai/CLIP.git@main#egg=clip
    - -e .
    #pip install -e git+https://github.com/openai/CLIP.git@main#egg=clip
    #pip install -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
    #pip install -e.
 #因为环境无法稳定访问github,导致相关包安装失败
 #建议执行虚拟环境创建前,开启FT的github加速。

6、文生图

python scripts/txt2img.py --prompt "egg in the pocket" --plms --n_samples 2
#因为环境无法稳定访问github,导致相关包安装失败,
#执行scripts/txt2img.py过程会报无数次 ModuleNotFoundError: No module named XX的错误
#解决办法:pip install 对应的模块名称,解决不了google
#1、最后pip install方式因为版本不对,跑.py还是会失败,所以建议开通FT,能够访问境外网站和github,避免因为版本不对,因为造成无法使用问题
#2、即便开了github的网际快车,还是会遇到报错的问题,需要再开始FT的Http/https的代理。

#都设置后,还会出现包未安装的现象,执行如下命令进行安装。
#apt-get install libsm6
#apt-get install -y libxrender-dev

#生成的文件在:/root/stable-diffusion/outputs/txt2img-samples/samples/

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2023年12月5日
下一篇 2023年12月5日

相关推荐