AI繪圖-環(huán)境搭建(Linux)

一、選擇服務(wù)器

本地安裝

通過 https://github.com/AUTOMATIC1111/stable-diffusion-webui,查看是否滿足條件,并且磁盤剩余空間要大(我使用的服務(wù)器,占用了20多個G,只有一個默認基底模型)。

服務(wù)器安裝

阿里云提供了云實驗室,免安裝,也有活動,也可以選擇。
騰訊云服務(wù)器,https://cloud.tencent.com/act/pro/2023spring?from=yunmember&page=seckill_season,有活動,可選擇如下。

image.png

本文以在 centos 服務(wù)器自己安裝為例。

二、安裝軟件

整個安裝過程相對坎坷,遇到問題先看文末的問題列表,如果沒有可去谷歌或者 stable-diffusion-webui github issue 中進行搜索。

安裝 git

yum install git

安裝 python3.10

官方需要 >= python3.10.6,此處安裝或者升級 python3 到 python3.10.6,python2 系統(tǒng)自帶,如果沒有也需要安裝,后續(xù) yum 需要用到。

//下載
wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz

//解壓
tar -zxvf Python-3.10.6.tgz

//構(gòu)建安裝
cd Python-3.10.6/
./configure
make && make install

// python與python3命令換軟連
mv /usr/bin/python /usr/bin/python.bak
mv /usr/bin/python3 /usr/bin/python3.bak
ln -s /usr/local/bin/python3.10 /usr/bin/python
ln -s /usr/local/bin/python3.10 /usr/bin/python3

// pip換軟連
ln -s /usr/local/bin/pip3 /usr/bin/pip
ln -s /usr/local/bin/pip3 /usr/bin/pip3

修改 yum 配置文件

原因:https://blog.csdn.net/zsl10/article/details/52315319

sudo vi yum // 修改 #!/usr/bin/python 為 #!/usr/bin/python2.7
sudo vi /usr/libexec/urlgrabber-ext-down // 修改 #!/usr/bin/python 為 #!/usr/bin/python2.7

安裝 stable-diffusion-webui

// 設(shè)置git參數(shù),加快clone速度
git config --global http.postBuffer 524288000

// clone
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

// 安裝依賴庫
cd stable-diffusion-webui/
sudo  pip install -r requirements_versions.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

啟動 stable-diffusion-webui

nohup python -u launch.py --listen --port 8008 > runtime.log 2>&1 &

啟動過程中會下載較多的倉庫,耐心等待,或者按照問題列表的方式進行處理。查看日志。標識啟動成功。

Model loaded in 3.3s (create model: 0.5s, apply weights to model: 0.7s, apply half(): 0.3s, load VAE: 1.2s, move model to device: 0.6s).
Running on local URL:  http://0.0.0.0:8008

三、配置外網(wǎng)訪問

如果是本地啟動,啟動后,“本地ip:port” 訪問即可。如果是服務(wù)器,啟動后,通過“公網(wǎng)ip:port”訪問,如果通過域名,需要配置 nginx。

下載 nginx

yum install nginx

配置 nginx

vi /etc/nginx/nginx.conf

修改內(nèi)容如下:(列出核心修改,其他內(nèi)容不變)

    server {
        listen       80;
        server_name  www.xxx.cn; // 域名或者 localhost
        ... 
        location / {
           proxy_pass http://127.0.0.1:8008; // 代理地址,即stable-diffusion 地址
        }
        error_page 404 /404.html;
        location = /404.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }

在這里我使用的是域名的方式。瀏覽器訪問 http://www.xxx.cn,即可。如果沒有域名,使用服務(wù)器外網(wǎng)IP進行訪問即可。最終效果如下圖所示,該界面是響應(yīng)式的,手機也可訪問。

image.png

四、開始作圖

image.png

基底模型

基底模型決定了出圖的整體風格。SD 自帶了一個 v1-5-pruned-emaonly.safetensors,還可以從 https://civitai.com/ 選擇下載合適的 checkpoint 類型的模型,上傳到 SD 的 models/Stable-diffusion/ 目錄里,我安裝了如下三個模型:

  • 默認:v1-5-pruned-emaonly.safetensors
  • 通用逼真人物:chilloutmix_NiPrunedFp32Fix.safetensors
  • 蒂法專用模型:tifaMeenow_tifaV2.safetensors

正向語義

組成:主體定義 + 主體形容 + 正向通用,多個詞直接直接英文逗號隔開,無需標準的英語語句語法;權(quán)重語法可參考 這里,通常先寫出主體定義 + 主體形容,之后根據(jù)需求調(diào)整權(quán)重。
參考:從 https://civitai.com/ 點擊模型,查看語義,直接復制或者進行參考;
通用的正向語義詞如下所示:

(photorealistic:1.4),best quality,realistic,masterpiece,extremely detailed,highres

用戶定義的語義可通過 語義生成器 來做或者使用 chatGPT 來生成。

負向語義

直接寫死一下這個就行,或者根據(jù)需求進行修改,通用的負向語義詞:

multiple breasts, (mutated hands and fingers:1.5 ), (long body :1.3), (mutation, poorly drawn :1.2) , black-white, bad anatomy, liquid body, liquid tongue, disfigured, malformed, mutated, anatomical nonsense, text font ui, error, malformed hands, long neck, blurred, lowers, lowres, bad anatomy, bad proportions, bad shadow, uncoordinated body, unnatural body, fused breasts, bad breasts, huge breasts, poorly drawn breasts, extra breasts, liquid breasts, heavy breasts, missing breasts, huge haunch, huge thighs, huge calf, bad hands, fused hand, missing hand, disappearing arms, disappearing thigh, disappearing calf, disappearing legs, fused ears, bad ears, poorly drawn ears, extra ears, liquid ears, heavy ears, missing ears, fused animal ears, bad animal ears, poorly drawn animal ears, extra animal ears, liquid animal ears, heavy animal ears, missing animal ears, text, ui, error, missing fingers, missing limb, fused fingers, one hand with more than 5 fingers, one hand with less than 5 fingers, one hand with more than 5 digit, one hand with less than 5 digit, extra digit, fewer digits, fused digit, missing digit, bad digit, liquid digit, colorful tongue, black tongue, cropped, watermark, username, blurry, JPEG artifacts, signature, 3D, 3D game, 3D game scene, 3D character, malformed feet, extra feet, bad feet, poorly drawn feet, fused feet, missing feet, extra shoes, bad shoes, fused shoes, more than two shoes, poorly drawn shoes, bad gloves, poorly drawn gloves, fused gloves, bad cum, poorly drawn cum, fused cum, bad hairs, poorly drawn hairs, fused hairs, big muscles, ugly, bad face, fused face, poorly drawn face, cloned face, big face, long face, bad eyes, fused eyes poorly drawn eyes, extra eyes, malformed limbs, more than 2 nipples, missing nipples, different nipples, fused nipples, bad nipples, poorly drawn nipples, black nipples, colorful nipples, gross proportions. short arm, (((missing arms))), missing thighs, missing calf, missing legs, mutation, duplicate, morbid, mutilated, poorly drawn hands, more than 1 left hand, more than 1 right hand, deformed, (blurry), disfigured, missing legs, extra arms, extra thighs, more than 2 thighs, extra calf, fused calf, extra legs, bad knee, extra knee, more than 2 legs, bad tails, bad mouth, fused mouth, poorly drawn mouth, bad tongue, tongue within mouth, too long tongue, black tongue, big mouth, cracked mouth, bad mouth, dirty face, dirty teeth, dirty pantie, fused pantie, poorly drawn pantie, fused cloth, poorly drawn cloth, bad pantie, yellow teeth, thick lips, bad cameltoe, colorful cameltoe, bad asshole, poorly drawn asshole, fused asshole, missing asshole, bad anus, bad pussy, bad crotch, bad crotch seam, fused anus, fused pussy, fused anus, fused crotch, poorly drawn crotch, fused seam, poorly drawn anus, poorly drawn pussy, poorly drawn crotch, poorly drawn crotch seam, bad thigh gap, missing thigh gap, fused thigh gap, liquid thigh gap, poorly drawn thigh gap, poorly drawn anus, bad collarbone, fused collarbone, missing collarbone, liquid collarbone, strong girl, obesity, worst quality, low quality, normal quality, liquid tentacles, bad tentacles, poorly drawn tentacles, split tentacles, fused tentacles, missing clit, bad clit, fused clit, colorful clit, black clit, liquid clit, QR code, bar code, censored, safety panties, safety knickers, beard, furry ,pony, pubic hair, mosaic, excrement, faeces, shit

采樣器與采樣步數(shù)

采樣器:全部采樣器介紹。我常用的 Euler(基礎(chǔ)、快);DPM++ SDE Karras。
采樣步數(shù):不斷繪制的過程,每一步都是在之前生成的基礎(chǔ)上進行精修,通常 20~40 之間。

擴散度

通常 5~10 之間,如果太高,風格會變,色彩過于飽和(油畫類)

隨機種子

默認 -1,表示隨機。如果保持和已生成圖片一致,用于圖片微調(diào)。

其他功能

局部微調(diào)

image.png

Lora

在基底模型的基礎(chǔ)上繼續(xù)增加 Lora 模型,進行訓練。Lora 可去 https://civitai.com/ 進行下載,之后放到 SD的 models/Lora/ 內(nèi)。

image.png

ControllNet

AI 模仿原始圖的動作進行繪畫,用于指定動作繪制。

五、一些示例

示例1

正向語義:

best quality, masterpiece, highres, 1girl,china dress,hair ornament,necklace, jewelry,Beautiful face,upon_body, tyndall effect,photorealistic, dark studio, rim lighting, two tone lighting,(high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, volumetric lighting, candid, Photograph, high resolution, 4k, 8k, Bokeh

負向語義:

上面通用的負向語義

其他配置:


image.png

最終效果:


00014-443568080.png

示例2

附、遇到的報錯和阻塞

1、安裝Python3后yum無法使用

解決方案:https://blog.csdn.net/zsl10/article/details/52315319

2、python setup.py bdist_wheel 報錯

解決方案:https://blog.csdn.net/qq_40236497/article/details/125633599

3、ModuleNotFoundError: No module named '_ctypes'

解決方案:https://blog.51cto.com/u_15162069/2887202

4、ModuleNotFoundError: No module named '_ssl'

解決方案:安裝 openssl-1.1.1,配置python,重新安裝python
第一步:安裝 openssl-1.1.1

cd /home/
wget http://www.openssl.org/source/openssl-1.1.1.tar.gz --no-check-certificate
tar -zxf openssl-1.1.1.tar.gz
cd openssl-1.1.1/
mkdir /usr/local/openssl
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl
make && make install

第二步:配置 Python
vi /home/Python-3.10.6/Modules/Setup 配置如下內(nèi)容

_socket socketmodule.c
OPENSSL=/usr/local/openssl
_ssl _ssl.c \
     -I$(OPENSSL)/include -L$(OPENSSL)/lib \
     -lssl -lcrypto

第三步:重新安裝 Python

cd /home/Python-3.10.6/
make clean
./configure
make && make install

5、ModuleNotFoundError: No module named '_bz2'

yum install bzip2-devel

之后重新安裝 Python。

6、ModuleNotFoundError: No module named '_lzma'

yum install -y xz-devel

之后重新安裝 Python。

7、git -C unknown option

https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/8193

8、啟動過程 clone 各種倉庫慢

第一種方式:配置git代理
第二種方式:本地下載倉庫,然后根據(jù)clone慢導致的報錯上傳到指定位置,并且進行重命名。例如。/home/stable-diffusion-webui/repositories/taming-transformers/

8、啟動過程中下載模型慢

Downloading: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors" to /home/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors

手動下載 v1-5-pruned-emaonly.safetensors,然后上傳到 /home/stable-diffusion-webui/models/Stable-diffusion/

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,461評論 6 532
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 98,538評論 3 417
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,423評論 0 375
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,991評論 1 312
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,761評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 55,207評論 1 324
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,268評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,419評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 48,959評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 40,782評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,983評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,528評論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 44,222評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,653評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,901評論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,678評論 3 392
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,978評論 2 374

推薦閱讀更多精彩內(nèi)容