1、安裝Nvidia驅(qū)動、cuda版本等
略文章來源:http://www.zghlxwxcb.cn/news/detail-582707.html
2、安裝anaconda環(huán)境
略
3、安裝git
#git工具的安裝參考下面命令
apt-get update -y a
pt-get upgrade -y
apt install git
4、下載源碼和模型參數(shù)文件
#1、下載源碼
git clone https://github.com/CompVis/stable-diffusion.git
#2、下載模型參數(shù)文件,以下示例為v1.4版本,大約7GB
wget https://xujianhua-bj.tos-cn-beijing.volces.com/sd-v1-4-full-ema.ckpt
#3、設置模型參數(shù)存放位置
#git下來的stable-diffusion文件夾路徑中創(chuàng)建stable-diffusion-v1目錄
mkdir -p /root/stable-diffusion/models/ldm/stable-diffusion-v1/
#將下載的模型參數(shù)文件改名為 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創(chuàng)建 ldm 虛擬環(huán)境
#切換清華源,便于后續(xù)生成環(huán)境,下載python包
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
//注意:火山引擎FT的只開github的加速,不開http/https代理。因為設置http/https代理, 執(zhí)行conda env create -f environment.yaml會報錯。文章來源地址http://www.zghlxwxcb.cn/news/detail-582707.html
#進入之前的源碼解壓目錄
cd stable-diffusion
conda env create -f environment.yaml
conda activate ldm
#environment.yaml的內(nèi)容
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.
#因為環(huán)境無法穩(wěn)定訪問github,導致相關(guān)包安裝失敗
#建議執(zhí)行虛擬環(huán)境創(chuàng)建前,開啟FT的github加速。
6、文生圖
python scripts/txt2img.py --prompt "egg in the pocket" --plms --n_samples 2
#因為環(huán)境無法穩(wěn)定訪問github,導致相關(guān)包安裝失敗,
#執(zhí)行scripts/txt2img.py過程會報無數(shù)次 ModuleNotFoundError: No module named XX的錯誤
#解決辦法:pip install 對應的模塊名稱,解決不了google
#1、最后pip install方式因為版本不對,跑.py還是會失敗,所以建議開通FT,能夠訪問境外網(wǎng)站和github,避免因為版本不對,因為造成無法使用問題
#2、即便開了github的網(wǎng)際快車,還是會遇到報錯的問題,需要再開始FT的Http/https的代理。
#都設置后,還會出現(xiàn)包未安裝的現(xiàn)象,執(zhí)行如下命令進行安裝。
#apt-get install libsm6
#apt-get install -y libxrender-dev
#生成的文件在:/root/stable-diffusion/outputs/txt2img-samples/samples/
到了這里,關(guān)于Stable diffusion環(huán)境部署搭建的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!