1. 首先安裝基本工具
# 安裝python環(huán)境
sudo apt install wget git
若已經安裝過請忽略
2. 安裝miniconda(也可以自己下載python)
下載最新的安裝包
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
執(zhí)行安裝
./Miniconda3-latest-Linux-x86_64.sh
一路回車,遇到選擇就yes(切記要yes,不然要手動添加環(huán)境變量)
刷新環(huán)境
source .bashrc
此時命令行輸入python,看到是3.10版本的就對了
(base) root@localhost:~# python
Python 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
后續(xù)步驟可以用conda新建一個虛擬環(huán)境進行,我的服務器是臨時的,所以就直接在base環(huán)境下進行了
3. git拉取項目到本地
執(zhí)行
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
進入項目目錄下
cd stable-diffusion-webui/
4. 安裝對應Python依賴包
首先安裝pytorch
和torchvision
,若是GPU環(huán)境的用戶需要安裝與cuda版本對應的torch
,cpu環(huán)境則無具體要求
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
然后給pip換上中科大的源,也可以換清華源或阿里源
pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
接著安裝對應依賴
pip install -r requirements_versions.txt
5. 從huggingface下載預訓練模型參數
進入模型存放對應目錄
cd models/Stable-diffusion/
下載一個模型,這里可以根據自己的需要下載
wget https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4-full-ema.ckpt
6. 啟動項目
到這一步網上很多方法都是直接執(zhí)行根目錄下的webui.sh,我執(zhí)行時有報錯,就換了一種方式
回到項目根目錄,執(zhí)行launch.py
文件,啟動web服務,并指定監(jiān)聽端口為1234(端口號隨意)
python3 launch.py --port 1234 --listen
若為cpu環(huán)境,則需提前執(zhí)行
export COMMANDLINE_ARGS=--skip-torch-cuda-test
并且在運行時加入no-half
python3 launch.py --no-half --port 1234 --listen
啟動后安裝很多依賴以及克隆相應github倉庫,過程有報錯的可以看附錄解決方案并重新執(zhí)行這一步
若出現以下內容則說明啟動成功
此時訪問http://127.0.0.1:1234
即可使用
7. 公網訪問
若想讓服務能在公網上被其他用戶訪問,則需進入weibu.py
文件,修改對應代碼,將shared.demo.launch()第一行參數改為share=True。
然后重新啟動項目,此時能看到公網地址,說明成功
訪問以上臨時的公網地址就可以讓別人也使用你的AI作圖了
8. 漢化擴展
在任意目錄下克隆中文擴展地址
git clone https://github.com/VinsonLaro/stable-diffusion-webui-chinese
進入下載好的文件夾,把localizations
文件夾內的Chinese-All.json
和Chinese-English.json
復制到stable-diffusion-webui\localizations
目錄下,如下
啟動web服務后,點擊Settings
,左側點擊User interface
界面,在界面里最下方的Localization (requires restart)
,選擇Chinese-All
或者Chinese-English
,點擊界面最上方的黃色按鈕Apply settings
,再點擊右側的Reload UI
即可完成漢化。
漢化后的頁面文章來源:http://www.zghlxwxcb.cn/news/detail-423053.html
附:遇到的錯誤
- 報錯RuntimeError: Couldn’t clone Stable Diffusion。
解決辦法:手動clone
git clone https://github.com/Stability-AI/stablediffusion.git "/root/stable-diffusion-webui/repositories/stable-diffusion-stability-ai"
- 報錯gnutls_handshake() failed: The TLS connection was non-properly terminated
解決辦法:在執(zhí)行時使用http
而不是https
,替換
git clone https://github.com/Stability-AI/stablediffusion.git
為文章來源地址http://www.zghlxwxcb.cn/news/detail-423053.html
git clone http://github.com/Stability-AI/stablediffusion.git
- 報錯RuntimeError: Couldn’t install open_clip。安裝open_clip失敗
解決辦法:進入launch.py文件,找到openclip_package
部分代碼,修改對應部分代碼為
openclip_package = os.environ.get('OPENCLIP_PACKAGE', "git+https://gitee.com/ufhy/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b"))
到了這里,關于最詳細的Ubuntu服務器搭建Stable-Diffusion教程(無顯卡,僅用CPU)的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!