[논문리뷰] High-Resolution Image Synthesis with Latent Diffusion Models (LDM, 2022)

김민서·2024년 7월 11일
1

Diffusion Models

목록 보기
6/8

1. Introduction

  • Diffusion Models

    • 기존 모델들(Autoregressive model, GANs)의 단점을 보완
      - mode collapse, training instabilities 해결
    • SOTA performance
    • RGB image를 그대로 다루기 때문에 high-dimensional space에서 계산이 이루어진다
      • training도 inference도 오래 걸림 + 자원 낭비
  • departure to latent space

    • learning은 two-stage로 나눌 수 있음
      1) perceptual compression : high-freq details를 제거하고 semantic variation은 거의 안 배우는 구간
      2) semantic compression : semantic & conceptual composition of data를 배우는 구간, 우리가 보통 생각하는 'learning'

    • basic idea: Let's find a perceptually equivalent,but computationally more suitable space

  • Latent Diffusion Models

    • two distinct phases
      1) data space와 perceptually equivalent한 low-dim representational space로 보내는 autoencoder 학습
      2) learned latent space에서 Diffusion model 학습
    • universal autoencoder 한 번만 학습하면 여러 DMs에 universal하게 적용 가능

3. Method

3.1. Perceptual Image Compression

  • image x  RH×W×3x\ \in\ \mathbb{R}^{H\times W\times 3}를 latent z  Rh×w×cz\ \in\ \mathbb{R}^{h\times w\times c}로 보내는 encoder/decoder
    • z=E(x)z=\mathcal{E}(x)
    • x~=D(E(x))\tilde{x}=\mathcal{D}(\mathcal{E}(x))
    • encoder가 이미지를 f=Hh=Wwf= \frac{H}{h}= \frac{W}{w}배만큼 downsample 시키는 과정으로 볼 수 있음
  • latent space의 variance가 커지는 것을 막기 위해 두 가지 regularizations를 실험해봄
    • KL-reg : learned latent와 standard normal을 비교한 KL-penalty를 약간 걸어주기
    • VQ-reg : decoder 단에서 vector quantized layer를 사용하기
  • autoencoder training
    • 자세한 내용은 appendix C에
    • discriminator DψD_{\psi}xxD(E(x))\mathcal{D}(\mathcal{E}(x))를 구분하도록 adversarial training

3.2. Latent Diffusion Models

  • 기존 DDPM loss
    LDM=Ex,ϵN(0,1),t[ϵϵθ(xt,t)22]L_{DM}=\mathbb{E}_{x,\epsilon \sim \mathcal{N}(0,1),t} \left[||\epsilon - \epsilon_{\theta}(x_{t},t) ||_{2}^{2} \right]
  • LDM은 xtx_{t}말고 latent space에 있는 ztz_{t}를 쓴다
    LLDM=EE(x),ϵN(0,1),t[ϵϵθ(zt,t)22]L_{LDM}=\mathbb{E}_{\mathcal{E}(x),\epsilon \sim \mathcal{N}(0,1),t} \left[||\epsilon - \epsilon_{\theta}(z_{t},t) ||_{2}^{2} \right]
  • advantages
    1) 모델이 important, semantic bits of data에 집중할 수 있다
    2) lower dimension에서 계산하니까 더 효율적이다
  • latent space에서 다뤄지는 기존 모델들과 달리 LDM에서는 이미지별 inductive bias(??)를 활용할 수 있다

3.3. Conditioning Mechanisms

  • conditioning
    • 다른 생성모델들처럼 data distribution p(x)p(x) 대신 condition yy를 넣은 p(xy)p(x|y)를 배우게 하면 된다
    • ϵθ(zt,t)\epsilon_{\theta}(z_{t},t) 대신 ϵθ(zt,t,y)\epsilon_{\theta}(z_{t},t,y) 사용
    • 그런데 아직은 다양한 종류의 condition을 다루지는 못함
  • cross-attention mechanism
    • 어떤 modality의 yy가 들어와도 작동하도록 domain specific encoder τθ\tau_{\theta}를 학습시키자
      • yy를 intermediate representation τθ(y)RM×dτ\tau_{\theta}(y) \in \mathbb{R}^{M \times d_{\tau}}로 project
    • τθ(y)\tau_{\theta}(y)는 cross-attention layer를 통해서 UNet 중간중간에 매핑할 수 있다
      Attention(Q,K,V)=softmax(QKTd)V\mathrm{Attention}(Q,K,V) = \mathrm{softmax}\left(\frac{QK^{T}}{\sqrt{d}} \right) \cdot V
      Q=WQ(i)ϕi(zt),   K=WK(i)τθ(y),   V=WV(i)τθ(y)Q=W_{Q}^{(i)}\cdot \phi_{i}(z_{t}),\ \ \ K=W_{K}^{(i)}\cdot \tau_{\theta}(y),\ \ \ V=W_{V}^{(i)}\cdot \tau_{\theta}(y)
      • 여기서 ϕi(zt)\phi_{i}(z_{t})ϵθ\epsilon_{\theta}를 implement하는 UNet 중간 representation
      • WV(i)Rd×dϵiW_{V}^{(i)} \in \mathbb{R}^{d\times d_{\epsilon}^{i}}, WQ(i)Rd×dτW_{Q}^{(i)} \in \mathbb{R}^{d\times d_{\tau}}, WK(i)Rd×dτW_{K}^{(i)} \in \mathbb{R}^{d\times d_{\tau}}는 모두 learnable projection matrices
  • Objective
    LLDM=EE(x),ϵN(0,1),t[ϵϵθ(zt,t,τθ(y))22]L_{LDM}=\mathbb{E}_{\mathcal{E}(x),\epsilon \sim \mathcal{N}(0,1),t} \left[||\epsilon - \epsilon_{\theta}(z_{t},t,\tau_{\theta}(y)) ||_{2}^{2} \right]
    • ϵθ\epsilon_{\theta}τθ\tau_{\theta}는 동시에 optimized된다
    • τθ\tau_{\theta} 설계 방식은 자유

4. Experiments

4.1. On Perceptual Compression Tradeoffs

  • downsampling factor f{1,2,4,8,16,32}f \in \{1,2,4,8,16,32 \}로 비교 실험
    • LDMLDM-1 = 기존 DM
  • Results
    • LDMLDM-{1,2}는 학습이 느렸고
    • LDMLDM-{32}는 너무 압축해서 information loss가 일어난 탓에 quality가 크게 떨어졌다
    • LDMLDM-{4,8}이 sweet spot

4.2. Image Generation with Latent Diffusion

  • LDMLDM-{4,8}과 기존 generative models를 비교
  • unconditional 256x256 generation
  • Results
    • 잘 나왔다

4.3. Conditional Latent Diffusion

  • cross-attention based conditioning의 활용

  • sampling beyond 2562256^{2}

    • 256x256으로 학습시키고 그보다 더 큰 resolution으로 샘플링이 가능함

4.4. Super-Resolution with Latent Diffusion

  • low resolution image를 condition으로 넣어서 SR을 할 수 있다
  • 실험 결과 기존 모델인 SR3랑 성능이 엇비슷했음

4.5. Inpainting with Latent Diffusion

5. Limitations

  • 기존 DMs보다는 빨라지긴 했지만 여전히 GAN보다 훨씬 느리다
  • 정확도가 중요한 task에서는 쓰일 수 있을지 여전히 의문이다

0개의 댓글