[๋ ผ๋ฌธ๋ฆฌ๋ทฐ] Adding Conditional Control to Text-to-Image Diffusion Models
๐ CVPR 2023
Introduction
๊ธฐ์กด ์ฐ๊ตฌ๋ค์ ํ๊ณ์
- ํ ์คํธ๋ง์ผ๋ก ํ๋กฌํํธ๋ง์ผ๋ก๋ ์์ธ, ๋ ์ด์์ ๋ฑ ๋ณต์กํ ์ด๋ฏธ์ง ๊ตฌ์ฑ์ ์ ๋ฐํ๊ฒ ์ ์ดํ๊ธฐ ์ด๋ ต๋ค.
์ ์ํ๋ ๋ฐฉ๋ฒ
Stable Diffusion๊ณผ ๊ฐ์ ๋ํ T2I ๋ชจ๋ธ์ ๊ธฐ๋ฐ์ผ๋ก, ์ธ๋ถ ์ด๋ฏธ์ง ์กฐ๊ฑด์ ์ฌ์ฉํ์ฌ ๋ ์ ๋ฐํ ์ ์ด๋ฅผ ๊ฐ๋ฅํ๊ฒ ํ๋ค.
- ๊ธฐ์กด ํ๋ผ๋ฏธํฐ๋ฅผ ๊ณ ์ ํ๊ณ , ํ์ต ๊ฐ๋ฅํ ๋ณต์ฌ๋ณธ์ธ ์ธ์ฝ๋ฉ ๊ณ์ธต์ ์๋ณธ๊ณผ zero convolution layer๋ก ์ฐ๊ฒฐํ๋ค.
- Zero convolution layer๋ ์ฒ์์ ๊ฐ์ค์น๊ฐ 0์ผ๋ก ์ด๊ธฐํ๋ convolution์ ์๋ฏธํ๋ฉฐ,
Methods
1. ControlNet
ControlNet์ ์๋ ๊ทธ๋ฆผ๊ณผ ๊ฐ์ด ์ถ๊ฐ์ ์ธ ์กฐ๊ฑด์ ์ ๊ฒฝ๋ง ๋ด๋ถ์ ์ฃผ์ ํ๋ค.
$\Theta$๋ก ํ๋ผ๋ฏธํฐํ๋์ด ์๋ ์ ๊ฒฝ๋ง ๋ธ๋ก์ ์๋์ ๊ฐ์ด ํํํ๋ค.
์์ ์์์์ $\mathbf{x}$์ $\mathbf{y}$๋ ์ผ๋ฐ์ ์ผ๋ก 2D feature์ด๋ฉฐ, $\mathbf{x}\in\mathbb{R}^{h\times w\times c}$ ํํ๋ฅผ ๊ฐ์ง๋ค.
์ฌ์ ํ์ต๋ ๋ธ๋ก์ ControlNet์ ์ถ๊ฐํ๊ธฐ ์ํด $\Theta_c$๋ก ํ๋ผ๋ฏธํฐํ๋์ด ์๋ trainable copy ๋ธ๋ก์ ์์ฑํ๋ค. ์ด ๋ธ๋ก์ ์ธ๋ถ ์กฐ๊ฑด $\mathbf{c}$๋ฅผ ์ ๋ ฅ์ผ๋ก ๋ฐ๋๋ค.
Trainable copy ๋ธ๋ก์ ์๋ณธ๊ณผ zero convolution $\mathcal{Z}(\cdot;\cdot)$์ผ๋ก ์ฐ๊ฒฐ๋๋ฉฐ, zero convolution์ ์ด๊ธฐ์ ๊ฐ์ค์น์ ๋ฐ์ด์ด์ค๊ฐ ๋ชจ๋ 0์ผ๋ก ์ด๊ธฐํ๋ 1x1 convolution์ ์๋ฏธํ๋ค.
ControlNet ๋ธ๋ก์ ์ถ๋ ฅ์ ์๋์ ๊ฐ์ด ํํ๋ ์ ์๋ค.
\[\mathbf{y}_c=\mathcal{F}(\mathbf{x};\Theta)+\mathcal{Z}\left( \mathcal{F}\left(\mathbf{x}+\mathcal{Z}(\mathbf{c;\Theta_{z1}});\Theta_C\right);\Theta_{z2} \right)\]Zero convolution์ ์ํด ์ด๊ธฐ์๋ $\mathbf{y}_c=\mathbf{y}$๊ฐ ๋๋ค. ์ด ๋๋ถ์ ๋ฌด์์๋ก ์ด๊ธฐํ๋ ํ๋ผ๋ฏธํฐ๊ฐ ํ์ต ์ด๊ธฐ์ trainable copy ๋ธ๋ก์ hidden state์ ์ํฅ์ ์ฃผ๋ ๋ฌธ์ ๋ฅผ ๋ฐฉ์งํ๋ค. ์ฆ, backbone์ ๋ณดํธํ๋ฉฐ, $\mathbf{c}$์ ์ํฅ์ ์ ์ง์ ์ผ๋ก ๋ฐ์ํ๊ฒ ํ๋ค.
2. ControlNet for Text-to-Image Diffusion
ControlNet์๋ Stable Diffusion์์์ ๋์ผํ๊ฒ Prompt $\mathbf{c}_t$์ timestep $\mathbf{t}$๊ฐ ์ ๋ ฅ์ผ๋ก ๋ค์ด๊ฐ๋ค. ์ด๋, Text prompt๋ CLIP์ผ๋ก ์ธ์ฝ๋ฉ๋๊ณ , timestep์ positional encoding์ผ๋ก ์ธ์ฝ๋ฉ๋๋ค.
ControlNet ๊ตฌ์กฐ๋ UNet์ ์ธ์ฝ๋์๋ง ์ ์ฉ๋๋ค. ๊ตฌ์ฒด์ ์ผ๋ก๋, Stable Diffusion์ 12๊ฐ์ Encoder Block๊ณผ 1๊ฐ์ Middle Block์ ํ๋ผ๋ฏธํฐ๋ฅผ ControlNet์ผ๋ก ๋ณต์ฌํ๋ค.
ControlNet์ Stable Diffusion์ ์ถ๊ฐํ๊ธฐ ์ํด, ๋จผ์ 512x512 ํฌ๊ธฐ์ ์กฐ๊ฑด ์ ๋ ฅ ์ด๋ฏธ์ง๋ฅผ 64x64์ latent ์ด๋ฏธ์ง๋ก ๋ณํํด์ผ ํ๋ค. ์ด๋ฅผ ์ํด 4๊ฐ์ convolution layer๋ก ๊ตฌ์ฑ๋ ์ธ์ฝ๋ $\mathcal{E}(\cdot)$์ ์ฌ์ฉํ๋ฉฐ, ์ ์ฒด ๋ชจ๋ธ๊ณผ ํจ๊ป ๊ณต๋์ผ๋ก ํ์ต๋๋ค.
\[\mathbf{c}_f=\mathcal{E}(\mathbf{c}_i)\]์์ ์์์์ $\mathbf{c}_f$๋ ControlNet์ ์ ๋ฌ๋๋ conditioning ๋ฒกํฐ๋ฅผ ์๋ฏธํ๋ค.
3. Training
์๋์ ์์์ ControlNet์ ํ์ฉํด ๋ํจ์ ๋ชจ๋ธ์ ํ์ธํ๋ํ ๋ ์ฌ์ฉ๋๋ ๋ชฉ์ ํจ์์ด๋ค.
\[\mathcal{L}=\mathbb{E}_{\mathbf{z}_0,\mathbf{t},\mathbf{c}_t,\mathbf{c}_f,\epsilon\sim\mathcal{N}(0,1)} \left[\lVert \epsilon-\epsilon_\theta(\mathbf z_t,t,\mathbf c_t,\mathbf c_f) \rVert^2_2\right]\]์ค์ ํ์ต ๋๋ 50%์ ํ๋ฅ ๋ก $\mathbf{c}_t$๋ฅผ ๋น ๋ฌธ์์ด๋ก ๋์ฒดํ์ฌ, ๋ชจ๋ธ์ด ํ ์คํธ ํ๋กฌํํธ ์์ด ์ด๋ฏธ์ง $\mathbf{c}_f$๋ง์ผ๋ก๋ ์๋ฏธ๋ฅผ ํ์ ํ๋๋ก ์ ๋ํด, ControlNet์ ๋ฅ๋ ฅ์ ๊ทน๋ํํ๋ค.
์คํ ๊ฒฐ๊ณผ, ๋ชจ๋ธ์ด ์กฐ๊ฑด์ ์ ์ง์ ์ผ๋ก ํ์ตํ๋ ๊ฒ์ด ์๋๋ผ ๊ฐ์๊ธฐ ์กฐ๊ฑด์ ๋ฐ๋ฅด๋ ํ์์ ๋ฐ๊ฒฌํ์๋ค.
์ ์๋ค์ ์์ ๊ฐ์ ํ์์ ๊ธ๊ฒฉํ ์๋ ด ํ์(sudden convergence phenomenon)์ด๋ผ๊ณ ๋ช ๋ช ํ์๋ค.
4. Inference
Classifier-free guidance resolution weighting
Stable Diffusion์ ๊ณ ํ์ง ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ธฐ ์ํด Classifier-Free Guidance๋ผ๋ ๊ธฐ๋ฒ์ ์์กดํ๋ค.
\[\epsilon_{\text{prd}}=\epsilon_{\text{uc}}+\beta_{\text{cfg}}(\epsilon_{\text{c}}-\epsilon_{\text{uc}})\]CFG๋ ์์ ๊ฐ์ด ์ ์๋๋ฉฐ, $\epsilon_{\text{uc}}$๋ unconditional ์ถ๋ ฅ, $\epsilon_{\text{c}}$๋ conditional ์ถ๋ ฅ์ ์๋ฏธํ๋ค.
ControlNet์ ํตํด ์กฐ๊ฑด ์ด๋ฏธ์ง๊ฐ ์ถ๊ฐ๋ ๊ฒฝ์ฐ, ์ด ์ด๋ฏธ์ง๋ $\epsilon_{\text{uc}}$์ $\epsilon_{\text{c}}$์ ๋ชจ๋ ์ถ๊ฐํ๊ฑฐ๋ ์ค์ง $\epsilon_{\text{c}}$์๋ง ์ถ๊ฐ๋ ์ ์๋ค.
CFG guidance์ ์ธ๊ธฐ๋ฅผ ์กฐ์ ํ๊ธฐ ์ํด CFG Resolution Weighting ๊ธฐ๋ฒ์ ๋์ ํ์๋ค. ์ด๋ ์กฐ๊ฑด์ ๋จผ์ $\epsilon_{\text{c}}$์๋ง ์ถ๊ฐํ๊ณ , ControlNet๊ณผ Stable Diffusion ์ฌ์ด์ ์ฐ๊ฒฐ์ ํด์๋ ๊ธฐ๋ฐ์ ๊ฐ์ค์น $w_i=\frac{64}{h_i}$๋ฅผ ๊ณฑํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๋ค.
์๋ ๊ทธ๋ฆผ์ ํ๋กฌํํธ๊ฐ ์๋ ์ํฉ ๊ฐ์ ๋ณต์กํ ๊ฒฝ์ฐ์์์ ๊ฒฐ๊ณผ๋ฅผ ๋ํ๋ธ๋ค.
- (b): ์กฐ๊ฑด์ $\epsilon_{\text{uc}}$์ $\epsilon_{\text{c}}$์ ๋ชจ๋ ์ถ๊ฐํ๋ฉด CFG guidance๊ฐ ์ฌ๋ผ์ง๋ค.
- (c): ์กฐ๊ฑด์ $\epsilon_{\text{c}}$์๋ง ์ถ๊ฐํ๋ฉด guidance๊ฐ ๋งค์ฐ ๊ฐํด์ง๋ค.
- (d): CFG-RW์ ์ฌ์ฉํ ๊ฒฝ์ฐ์ ์ด๋ฏธ์ง ํ์ง์ด ๊ฐ์ฅ ๋ฐ์ด๋๋ค.
Composing multiple ControlNets
์ฌ๋ฌ ๊ฐ์ ์กฐ๊ฑด ์ด๋ฏธ์ง๋ฅผ ๋์์ ์ ์ฉํ๊ณ ์ ํ ๊ฒฝ์ฐ, ๊ฐ ์กฐ๊ฑด์ ํด๋นํ๋ ControlNet์ ์ถ๋ ฅ๋ค์ ๋จ์ํ Stable Diffusion์ ๋ํด์ฃผ๊ธฐ๋ง ํ๋ฉด ๋๋ค.
Experiments
Qualitative Results
์์ ๊ทธ๋ฆผ์ ํ๋กฌํํธ ์์ด ๋ค์ํ condition์ ๋ฐ๋ฅธ ๋ชจ๋ธ์ ์ถ๋ ฅ ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ค๋ค.
Ablation Study







