雜談:ComfyUI很好用,但結果跟WebUI不一樣 / ComfyUI Is User-Friendly, But Results Differ From WebUI
繼上次把Forge裝起來後,我還是覺得生圖的方式太沒效率了,所以轉向尋求其他工具。這次嘗試的是Dify跟ComfyUI的結合。
- 基礎圖片 / Baseline
- Dify的Stable Diffusion整合工具 / Dify's Stable Diffusion Integration Tool
- 用ComfyUI繪圖 / Drawing with ComfyUI
- 為什麼ComfyUI跟WebUI會產出不同的結果? / Why Do ComfyUI and WebUI Produce Different Results?
- 小結 / In Closing
基礎圖片 / Baseline
我們先來試試看用同樣的配置在不同環境下的表現。由於Forge可以設定的比較詳細,我們先以Forge的設定為基礎。
這張希希助教的完整設定如下:
chinese new year, classic wood frame, detailed, bright colors, masterpiece, epic, <lora:lihui4JXK-b2-bf16-128-128-1-re1-ep3-768-DA-5015fix:0.7>, [(white background:1.5), ::24], (fisheye lens:1) OR isometric OR hexagon, depth of field, upper body, mid shot, little girl, 1girl, (short light pink hair:1.2), beautiful girl, beautiful eyes, pale skin, (red bow tie:1.2), (10 years old:1.2), (green eyes:1.2), a cute girl, <lora:koreanDollLikeness_v15:0.1>, magical girl, <lora:GenshinStickers:0.5>, eye light, bangs, (four heads:1), chinese white cheongsam, Emerald jewelry hairpin, red belt, smile, cinematic lighting, beautiful detailed shadow, white background Negative prompt: bad-hands-5, bad_prompt_version2-neg, easynegative, close-up, portrait, (big breasts), (fat), flat color, flat shading, bad anatomy, disfigured, deformed, malformed, mutant, gross, disgusting, out of frame, poorly drawn, extra limbs, extra fingers, missing limbs, blurry, out of focus, low res, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, artist name, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, ugly. watermarks, text, signature, blurry, messy, low quality, sketch by bad-artist, out of frame, cropped, (worst quality, low quality:1.4), (depth of field, blurry:1.2), (greyscale, monochrome:1.1), 3D face, cropped, lowres, text, jpeg artifacts, signature, watermark, username, blurry, artist name, trademark, watermark, title, multiple view, Reference sheet, curvy, plump, fat, muscular female, strabismus, watermark, Strapless, crown, Headband, veil, curls, bed, caption Steps: 20, Sampler: Euler a, Schedule type: Automatic, CFG scale: 7, Seed: 3641276826, Size: 512x512, Model hash: bd89eddf5a, Model: 7th_anime_v3_C, Token merging ratio: 0.1, Lora hashes: "lihui4JXK-b2-bf16-128-128-1-re1-ep3-768-DA-5015fix: dbfd1e49e2d9, koreanDollLikeness_v15: 9579fce696e0, GenshinStickers: 27e2a865a6b3", TI: "bad-hands-5, bad_prompt_version2-neg, easynegative", NGMS: 3.0, Hardware Info: "RTX 3060 12GB, QEMU Virtual version 2.5+, 31GB RAM", Time taken: 2.3 sec., Version: f2.0.1v1.10.1-1.10.1, Module 1: klF8Anime2VAE_klF8Anime2VAE
模型使用的是Stable Diffusion 1.5系列。SDXL跟Pony一直找不到類似的感覺,真令人困擾,到最後還是用回了SD 1.5。
以下是模型的相關資料:
- Base Model: 7th_anime_v3_C
https://huggingface.co/syaimu/7th_Layer/blob/main/7th_anime_v3/7th_anime_v3_C.ckpt - LORA: Gacha splash LORA - v4.0
https://civitai.com/models/13090/gacha-splash-lora - LORA: Genshin Sticker Chibi Style - GenshinStickersV1
https://civitai.com/models/20163/genshin-sticker-chibi-style - LORA: koreanDollLikeness_v15
https://civitai.com/models/24372/koreandolllikenessv15 - embedding: bad-hands-5
https://civitai.com/models/116230/bad-hands-5 - embedding: bad_prompt Negative Embedding
https://civitai.com/models/55700/badprompt-negative-embedding - embedding: EasyNegative
https://civitai.com/models/7808/easynegative - VAE: kl-f8-anime2 VAE
https://civitai.com/models/23906/kl-f8-anime2-vae
如果要圖片變得更細緻,需要搭配ControlNet的tile使用:
- control_v11f1e_sd15_tile [a371b31b]
https://huggingface.co/lllyasviel/control_v11f1e_sd15_tile/blob/main/diffusion_pytorch_model.bin
Dify的Stable Diffusion整合工具 / Dify's Stable Diffusion Integration Tool
再來我們嘗試在Dify盡可能做到同樣的配置。
我不太確定Stable Diffusion WebUI的LORA要怎麼輸入,先留了空格。不過我在Prompt裡面使用的LORA標籤,例如「<lora:GenshinStickers:0.5>」,看起來是有被Stable Diffusion WebUI的API正常解讀。所以此處應該留空即可。
負面提示詞無法接受變數,只能用固定字串設定。雖然平常不太會去變動負面提示詞,不過不能輕易地調整這點還是有點麻煩。
讓我們來看一下最後產生的結果。整體畫風依然保留著濃厚的7th_anime_v3_C風格,而服裝造型則確實受到Genshin Sticker Chibi Style等LORA的影響。然而Dify裡無法指定Seed,所以儘管我們使用的是同樣一套的Stable Diffusion WebUI,但亂數的結果使得我們難以產生一摸一樣的圖片。
參數確實有保存在PNG圖片裡面。
綜合以上結果來看,Dify雖然可以使用Stable Diffusion,但實際上能夠操控的範圍還是很有限。我想要批次產生100張圖片,也得要一次一次執行才行。因此最後我認為Dify整合Stable Diffusion這個方案難以滿足我的需求。
讓我們來看看有沒有其他方法吧。
用ComfyUI繪圖 / Drawing with ComfyUI
為了使用ComfyUI,我一樣用Docker撰寫了能夠運作ComfyUI的環境。整體來說ComfyUI需要的套件比Forge還少,所以安裝的過程也非常順利。需要注意的是啟動時需要加上參數「python main.py --listen 0.0.0.0」,然後模型的資料夾也跟Forge有很大的不同,需要各別調整。還好,在Docker裡面調整檔案路徑的對應,只是小菜一碟。
我在ComfyUI裡面額外安裝的套件如下:
- ComfyUI-Manager:管理套件的套件
https://github.com/ltdrdata/ComfyUI-Manager - WAS Node Suite:包含眾多功能的套件。我用它為圖片去背、以及將圖片保存到以日期命名的資料夾中。
https://github.com/WASasquatch/was-node-suite-comfyui - LoRA Tag Loader for ComfyUI:分析提示詞裡面的LORA標籤,載入對應的LORA模型。
https://github.com/badjeff/comfyui_lora_tag_loader
接下來讓我們在ComfUI裡面用類似的配置畫畫看。
首先LORA的載入我用了Load LoRA Tag,它號稱可以從提示詞裡面分析LORA標籤,例如「<lora:GenshinStickers:0.5>」,然後後續的對應就參考官方說明配置。
KSampler裡面跟WebUI不一樣的地方有三個。首先從PixelPirate的說明來看,sampler_name的enler_ancestral等於WebUI裡面的Euler A,因此可視為相等;scheduler裡面設置了normal,原本在WebUI是Automatic。ComfyUI有多一個選項denoise影響KSampler的初始噪點程度。相關介紹請看「AI圖像生成—K-Sampler準確解析」這篇。這個設定並未出現在WebUI。喔對了,這邊的seed使用的是Dify那張圖片的seed,所以動作感覺會跟Dify那張很像。
最後讓我們來看看產生的結果。嗯...雖然姿勢上跟WebUI的差不多,整體線條跟五官的畫法也都有反映出7th_anime_v3_C的味道,但顯然的LoRA效果都沒有正常輸入。
如果我們捨棄Load LoRA Tag,改成一個一個用Load LORA來輸入的話呢?
身上的物件稍微可以看到受到LORA的影響了,但整體色調卻變得非常藍。我之前使用ComfyUI到最後也是卡在這裡。這已經不是單純的調整色調可以解決的程度了。
為什麼ComfyUI跟WebUI會產出不同的結果? / Why Do ComfyUI and WebUI Produce Different Results?
上面兩張圖片是WebUI跟連結WebUI API的Dify產生的圖片。
而這張是ComfyUI產生的圖片。
儘管我盡可能讓兩者配置相同,但結果仍有很大的差異。為什麼會是如此呢?
https://github.com/comfyanonymous/ComfyUI/discussions/118
根據comfyanonymous的說法,因為ComfyUI的噪點是用CPU產生,而基於A1111的WebUI是用GPU產生。這使得兩種方法從一開始就註定產生不同的結果。
因此最好將ComfyUI視為另一套Stable Diffusion的繪圖工具,重新探索在ComfyUI畫圖的最佳實務做法。而不要將WebUI那套設定直接搬到ComfyUI,這樣可能比較好。
但我現在遭遇的問題是7th_anime_v3_C產出的圖片怎麽畫都偏藍。如果你有什麼好建議的話,請在下面留言幫我個忙吧,感謝!
小結 / In Closing
本來我使用試算表表格來管理希希助教的相關設定,但這些設定讓我覺得有點繁瑣,所以想趁這次機會,看能不能開發一個更容易配置的生圖架構。然而,Dify可以配置的程度過少,ComfyUI跟之前一樣無法重現WebUI的結果,使得我到最後又只能摸摸鼻子回頭繼續用WebUI。
Forge改版後的WebUI的確能夠提升繪圖的速度,但之前使用的一些擴充功能也無法安裝。我以前覺得最好用的是排程繪圖的功能,可以讓我快速修改幾個想要用的提示詞,然後讓WebUI在背後默默地產生圖片。但是在Forge似乎無法安裝這個擴充功能了。
因此,繞了一大圈之後,可能還是老樣子用提示詞管理模型,還是比較好的做法吧。有種滿滿的無奈啊。