[논문리뷰] ControlNet: Adding Conditional Control to Text-to-Image Diffusion Models
📑

[논문리뷰] ControlNet: Adding Conditional Control to Text-to-Image Diffusion Models

Category
딥러닝
Tags
Deep Learning
Paper Review
Diffusion Model
Published
March 8, 2023
Author
Jay

ControlNet: Adding Conditional Control to Text-to-Image Diffusion Models

notion image
 
 

0. Abstract

본 논문에서는 추가적인 input condition(edge map, segmentation map, key points 등)으로 pretrained diffusion model(Stable-Diffusion)을 컨트롤할 수 있게 하는 ControlNet을 소개한다. ControlNet은 task-specific condition을 학습할 수 있고, 50k 이하의 데이터셋에서도 robust하게 학습한다.

1. Introduction

이미지 생성을 위해 text를 작성하고나면 다음과 같은 질문이 든다.
  1. text-prompt 기반의 control이 우리의 니즈(상상한 이미지를 생성)를 잘 만족하는가?
  1. 넓은 범위의 문제조건과, 유저 컨트롤을 다루려면 어떤 프레임워크(text 이외의 input을 통한 생성)를 만들어야(build) 하는가?
  1. 특정 task에서 large model이 많은 이미지로부터 학습한 능력을 보존할 수 있는가?
 
이러한 질문들에 대답하기 위해, 저자는 다양한 image processing applications들을 조사했고, 세가지 발견을 할 수 있었다. (Data랑 Computation 적게 쓰는게 필요하다는 내용)
3가지 발견
  1. Task-specific 도메인에서 사용가능한 data 규모가 항상 general text2img data의 규모만큼 크지 않다.
      • 대부분의 specific-task에 대한 dataset은 100k under. LAION-5B 보다 작음
  1. Image processing task을 data-driven solution으로 수행하고자 할때, 항상 large computation이 사용가능하지는 않다.
      • 이 때문에 large model을 optimizing할 때 fast training methods가 중요 (개인 device에서도 가능할 정도)
  1. 다양한 image processing 문제들은 “문제 정의”, “유저 컨트롤”, “이미지 annotation”등에 있어 다양한 form을 가진다.
      • depth-to-image, pose-to-human과 같은 task들을 생각해보면, 분명 raw input에 대한 object나 scene 레벨의 interpretation이 필요하고, 이 경우 매번 “procedural”한 방식(denoising process에 contrain을 주고 → multi-head attention activation을 수정하고 → etc.. )으로 method를 만들어가는 것은 어렵다. 많은 Task에 학습된 solution을 위해서는 end-to-end 학습이 필수불가결하다.
 
 
ControlNet은 end-to-end neural network 구조로 Stable Diffusion 같은 large image diffusion model들을 특정 input condition으로 다룰 수 있게 한다. ControlNet은 large diffusion model의 weights를 “trainable copy”와 “locked copy”로 복제하는데, “trainable copy”가 conditional control을 배우기 위해 task-specific 데이터셋에 대해 학습된 것에 반해 “locked copy”는 기존 network의 capability를 보존한다. 이 두가지 neural net block은 특별한 종류의 convolution layer인 “zero convolution”와 연결된다. production-ready weight가 보존되기 때문에, 학습은 다른 규모의 dataset에 대해서도 robust하다. 또한, zero convolution이 새로운 노이즈를 더하지 않기 때문에, 학습 역시 diffusion 모델의 fine-tuning만큼 빠르다.
 
<1x1 convolution의 효과>
  • 학습 파라미터 감소 (채널수 변경)
  • 비선형성 추가
  • 객체 정보와 위치 정보의 독립적 연산
 

3. Method

3.1. ControlNet

ControlNet은 전체 neural network의 behavior를 통제하기 위해, neural network blocks의 input conditions를 조작한다. “network block”이란 neural layer들을 지칭하는데 “resnet” block, “conv-bn-relu” block, multi-head attention block, transformer block, etc 등이다.
2D feature를 사용할 때, 주어진 feature map 에 대하여 neural network block (는 parameter의 집합)는 를 다른 feature map인 로 transform 한다.
notion image
의 모든 파라미터는 lock되어 trainable copy 로 clone된다. 복사된 는 외부의 condition vector 로 학습되었다. 본 논문에서는 original 파라미터를 “locked copy”, 새로운 파라미터를 “trainable copy”라고 부른다. 기존 weight를 직접적으로 학습시키지 않고 이러한 copies들을 만든 이유는 dataset이 작을 때의 overfitting을 피하고, 수억장의 이미지로 부터 학습된 large model의 퀄리티를 보존하기 위함이다.
neural network block은 “zero convolution”이라 불리는 특별한 convolution layer 에 의해 연결되는데, 1x1 사이즈 conv layer로 weight와 bias가 모두 0으로 초기화된다. 는 두개의 parameter 인스턴스 을 사용하며, 아래와 같은 ControlNet structure를 구성한다.
학습된 ControlNet은 입력 조건에 대한 Semantic Content를 인식하는 기능을 한다. 즉,(Depth, Normal, Canny 등의 입력조건에 담긴 의미론적 내용을 생성에 반영한다.
notion image
zero convolution에서의 weight와 bias가 0으로 초기화되므로, 첫 번째 training step에서 우리는 아래와 같은 식을 얻을 수 있다.
notion image
그리고 이는 다음과 같이 해석된다
앞선 수식들이 나타내는 것은 ControlNet이 기존 neural network block에 적용되더라도, optimization되기 전에는 아무런 영향을 미치지 않는다는 것이다. 기존 모델 neural block들의 capability, functionality, result quality는 완벽하게 보존되며, 이후의 optimization 과정은 fine-tuning만큼 빠르다. (scratch부터 해당 layer들을 학습시키는 것보다 훨씬 빠르다)
간단하게 zero convolution layer의 gradient 계산을 살펴보자. weight , bias 인 1x1 convolution에 대해 spatial position()은 , channel index는 일때, 주어진 input map 에 대해 forward pass는 아래와 같다.
zero convolution은 , 이므로(optimization 전에는) 가 0이 아닌 곳에서, gradient는
notion image
와 같고, zero convolution이 feature term 에서의 gradient가 0이 되는 것을 야기할 수 있긴하지만, 우리는 weight 와 bias 의 gradient는 영향을 받지 않음을 확인할 수 있다. 첫번째 gradient descent에서 feature 가 0이 아닌 이상, weight 은 non-zero matrix로 optimize될 것이다. 쉽게 말하면 , 가 0으로 초기화 되더라도, 만 0이 아니면 학습이 되는 것을 확인할 수 있다.
이러한 방식으로, zero convolution은 0에서부터 optimized parameter가 되는 유니크한 connection layer가 된다.
 

3.2. ControlNet in Image Diffusion Model

Stable Diffusion을 예시로 쓴다.
notion image
Stable Diffusion은 학습과정 안정화를 위해, 512x512 이미지로 이루어진 전체 dataset을 64x64 “latent images”로 변환하는 pre-processing method를 사용한다(VQ-GAN과 유사). 이는 ControlNet역시 convolution size를 맞추기 위해 image-based condition을 64x64 feature space로 보내야 함을 의미한다. 논문에서는 4x4 kernel, 2x2 strided로 이루어진 tiny network 로 image-space condition 을 feature map 로 encode한다.
encoder는 512x512 condition을 64x64 feature map으로 만든다.
 

3.3. Training

time step , text prompt , task-specific condition(ControlNet의 input) , diffusion 알고리즘 , noisy image 에 대해 objective(loss)는 아래와 같다.
이 objective는 직접 fine-tuning에 사용될 수도 있다. 학습 과정 도중에 랜덤하게 text prompts 를 빈 string으로 만드는데, 이는 input condition map의 semantic한 콘텐츠를 인식하는 능력을 높이기 위함이다.
 

4. Experiment

더욱 다양한 실험결과는 논문 참고
notion image

4.1. Experiment Setting

모든 실험은 CFG=9.0, Sampler=DDIM, Steps=20 에서 수행되었다. 또한 세가지 타입의 프롬프트(No Prompt, Default Prompt=“a professional, detailed, high-quality image”, Automatic Prompt)를 사용하였다.
 

5. Limitation

notion image
 

Reference

 
< PREV