本篇文章介紹 Stable Diffusion web UI 的 Hires. fix 功能,用來提升圖片的解析度。

原理說明

Hires. fix 的原理其實很簡單,利用文生圖產生的圖片,進行放大之後再進行一次圖生圖,流程如下圖所示:
原理說明

功能區塊

在文生圖的頁面,採樣方法的下面可以找到 Hires. fix 的選項,勾起來就可以使用。同時下方會出現一些額外選項:
功能區塊

Upscaler

這是圖片放大時使用的方法,目前有以下的方法可以選擇

Latent, Latent (antialiased), Latent (bicubic), Latent (bicubic antialiased), Latent (nearest), Latent (nearest-exact), None, Lanczos, Nearest, ESRGAN_4x, LDSR, R-ESRGAN 4x+, R-ESRGAN 4x+ Anime6b, ScuNET, ScuNET PSNR, SwinIR_4x

後面會有實驗結果參考。

Hires steps

這是在進行圖生圖階段時使用的 Sampling steps,0 表示使用和文生圖一樣的步數。

Denoising strength

這是在進行圖生圖階段時使用的參數,作用和圖生圖時一樣,請參考 Stable Diffusion 教學 - web UI 圖生圖 (img2img)

Upscale by

這設定是要把文生圖的結果放大多少倍,原本是 512x512,這裡設定 2 的話就是變成 1024x1024。範圍為 1 - 4,預設為 2。這個設定和後面的兩個設定同時只會套用一個。

Resize width / height to

這是直接指定放大到明確的尺寸。範圍 0 - 2048,預設為 0。當兩個值都為 0 的時候使用 Upscale by。

實驗結果

這次使用的原圖為

以下為不同 Upscaler 和 Denoising Strength 的結果

Denoising Strength0.00.10.20.30.40.50.60.70.80.9
LatentLatent - Denoising Strength 0Latent - Denoising Strength 0.1Latent - Denoising Strength 0.2Latent - Denoising Strength 0.3Latent - Denoising Strength 0.4Latent - Denoising Strength 0.5Latent - Denoising Strength 0.6Latent - Denoising Strength 0.7Latent - Denoising Strength 0.8Latent - Denoising Strength 0.9
Latent (antialiased)Latent (antialiased) - Denoising Strength 0Latent (antialiased) - Denoising Strength 0.1Latent (antialiased) - Denoising Strength 0.2Latent (antialiased) - Denoising Strength 0.3Latent (antialiased) - Denoising Strength 0.4Latent (antialiased) - Denoising Strength 0.5Latent (antialiased) - Denoising Strength 0.6Latent (antialiased) - Denoising Strength 0.7Latent (antialiased) - Denoising Strength 0.8Latent (antialiased) - Denoising Strength 0.9
Latent (bicubic)Latent (bicubic) - Denoising Strength 0Latent (bicubic) - Denoising Strength 0.1Latent (bicubic) - Denoising Strength 0.2Latent (bicubic) - Denoising Strength 0.3Latent (bicubic) - Denoising Strength 0.4Latent (bicubic) - Denoising Strength 0.5Latent (bicubic) - Denoising Strength 0.6Latent (bicubic) - Denoising Strength 0.7Latent (bicubic) - Denoising Strength 0.8Latent (bicubic) - Denoising Strength 0.9
Latent (bicubic antialiased)Latent (bicubic antialiased) - Denoising Strength 0Latent (bicubic antialiased) - Denoising Strength 0.1Latent (bicubic antialiased) - Denoising Strength 0.2Latent (bicubic antialiased) - Denoising Strength 0.3Latent (bicubic antialiased) - Denoising Strength 0.4Latent (bicubic antialiased) - Denoising Strength 0.5Latent (bicubic antialiased) - Denoising Strength 0.6Latent (bicubic antialiased) - Denoising Strength 0.7Latent (bicubic antialiased) - Denoising Strength 0.8Latent (bicubic antialiased) - Denoising Strength 0.9
Latent (nearest)Latent (nearest) - Denoising Strength 0Latent (nearest) - Denoising Strength 0.1Latent (nearest) - Denoising Strength 0.2Latent (nearest) - Denoising Strength 0.3Latent (nearest) - Denoising Strength 0.4Latent (nearest) - Denoising Strength 0.5Latent (nearest) - Denoising Strength 0.6Latent (nearest) - Denoising Strength 0.7Latent (nearest) - Denoising Strength 0.8Latent (nearest) - Denoising Strength 0.9
Latent (nearest-exact)Latent (nearest-exact) - Denoising Strength 0Latent (nearest-exact) - Denoising Strength 0.1Latent (nearest-exact) - Denoising Strength 0.2Latent (nearest-exact) - Denoising Strength 0.3Latent (nearest-exact) - Denoising Strength 0.4Latent (nearest-exact) - Denoising Strength 0.5Latent (nearest-exact) - Denoising Strength 0.6Latent (nearest-exact) - Denoising Strength 0.7Latent (nearest-exact) - Denoising Strength 0.8Latent (nearest-exact) - Denoising Strength 0.9
NoneNone - Denoising Strength 0None - Denoising Strength 0.1None - Denoising Strength 0.2None - Denoising Strength 0.3None - Denoising Strength 0.4None - Denoising Strength 0.5None - Denoising Strength 0.6None - Denoising Strength 0.7None - Denoising Strength 0.8None - Denoising Strength 0.9
LanczosLanczos - Denoising Strength 0Lanczos - Denoising Strength 0.1Lanczos - Denoising Strength 0.2Lanczos - Denoising Strength 0.3Lanczos - Denoising Strength 0.4Lanczos - Denoising Strength 0.5Lanczos - Denoising Strength 0.6Lanczos - Denoising Strength 0.7Lanczos - Denoising Strength 0.8Lanczos - Denoising Strength 0.9
NearestNearest - Denoising Strength 0Nearest - Denoising Strength 0.1Nearest - Denoising Strength 0.2Nearest - Denoising Strength 0.3Nearest - Denoising Strength 0.4Nearest - Denoising Strength 0.5Nearest - Denoising Strength 0.6Nearest - Denoising Strength 0.7Nearest - Denoising Strength 0.8Nearest - Denoising Strength 0.9
ESRGAN_4xESRGAN_4x - Denoising Strength 0ESRGAN_4x - Denoising Strength 0.1ESRGAN_4x - Denoising Strength 0.2ESRGAN_4x - Denoising Strength 0.3ESRGAN_4x - Denoising Strength 0.4ESRGAN_4x - Denoising Strength 0.5ESRGAN_4x - Denoising Strength 0.6ESRGAN_4x - Denoising Strength 0.7ESRGAN_4x - Denoising Strength 0.8ESRGAN_4x - Denoising Strength 0.9
LDSRLDSR - Denoising Strength 0LDSR - Denoising Strength 0.1LDSR - Denoising Strength 0.2LDSR - Denoising Strength 0.3LDSR - Denoising Strength 0.4LDSR - Denoising Strength 0.5LDSR - Denoising Strength 0.6LDSR - Denoising Strength 0.7LDSR - Denoising Strength 0.8LDSR - Denoising Strength 0.9
R-ESRGAN 4x+R-ESRGAN 4x+ - Denoising Strength 0R-ESRGAN 4x+ - Denoising Strength 0.1R-ESRGAN 4x+ - Denoising Strength 0.2R-ESRGAN 4x+ - Denoising Strength 0.3R-ESRGAN 4x+ - Denoising Strength 0.4R-ESRGAN 4x+ - Denoising Strength 0.5R-ESRGAN 4x+ - Denoising Strength 0.6R-ESRGAN 4x+ - Denoising Strength 0.7R-ESRGAN 4x+ - Denoising Strength 0.8R-ESRGAN 4x+ - Denoising Strength 0.9
R-ESRGAN 4x+ Anime6bR-ESRGAN 4x+ Anime6b - Denoising Strength 0R-ESRGAN 4x+ Anime6b - Denoising Strength 0.1R-ESRGAN 4x+ Anime6b - Denoising Strength 0.2R-ESRGAN 4x+ Anime6b - Denoising Strength 0.3R-ESRGAN 4x+ Anime6b - Denoising Strength 0.4R-ESRGAN 4x+ Anime6b - Denoising Strength 0.5R-ESRGAN 4x+ Anime6b - Denoising Strength 0.6R-ESRGAN 4x+ Anime6b - Denoising Strength 0.7R-ESRGAN 4x+ Anime6b - Denoising Strength 0.8R-ESRGAN 4x+ Anime6b - Denoising Strength 0.9
ScuNETScuNET - Denoising Strength 0ScuNET - Denoising Strength 0.1ScuNET - Denoising Strength 0.2ScuNET - Denoising Strength 0.3ScuNET - Denoising Strength 0.4ScuNET - Denoising Strength 0.5ScuNET - Denoising Strength 0.6ScuNET - Denoising Strength 0.7ScuNET - Denoising Strength 0.8ScuNET - Denoising Strength 0.9
ScuNET PSNRScuNET PSNR - Denoising Strength 0ScuNET PSNR - Denoising Strength 0.1ScuNET PSNR - Denoising Strength 0.2ScuNET PSNR - Denoising Strength 0.3ScuNET PSNR - Denoising Strength 0.4ScuNET PSNR - Denoising Strength 0.5ScuNET PSNR - Denoising Strength 0.6ScuNET PSNR - Denoising Strength 0.7ScuNET PSNR - Denoising Strength 0.8ScuNET PSNR - Denoising Strength 0.9
SwinIR_4xSwinIR_4x - Denoising Strength 0SwinIR_4x - Denoising Strength 0.1SwinIR_4x - Denoising Strength 0.2SwinIR_4x - Denoising Strength 0.3SwinIR_4x - Denoising Strength 0.4SwinIR_4x - Denoising Strength 0.5SwinIR_4x - Denoising Strength 0.6SwinIR_4x - Denoising Strength 0.7SwinIR_4x - Denoising Strength 0.8SwinIR_4x - Denoising Strength 0.9

從上面的結果可以觀察到幾點現象

  1. Denoising strength 超過 0.7 和原圖差異過大,大部分方法在 0.5 效果都不錯。
  2. 最後三種方法 ScuNET, ScuNET PSNR, SwinIR_4x 會產生奇怪的色塊,造成後面差異過大。
  3. Latent 系列的放大都會變糊,Denoising strength 小於 0.4 都是糊的。

結論建議使用下面設定
Upscaler: None, Lanczos, Nearest, ESRGAN_4x, LDSR, R-ESRGAN 4x+, R-ESRGAN 4x+ Anime6b
Denoising strength: 0.3 - 0.7

延伸閱讀

上一篇 Stable Diffusion 教學 - Tiling