본문 바로가기

학부/논문 리뷰

BLIP-Diffusion: Pre-trained Subject Representation for Controllable Text-to-Image Generation and Editing 논문 리뷰

728x90
반응형

공통 스터디를 위해서 읽은 논문들을 가볍게 정리하고자 한다.

이번에는 BLIP diffusion model이며, CLIP-diffusion을 이어 BLIP 모델을 활용한 버전인 것 같다.

아직 BLIP에 대한 논문을 자세하게 읽어보지 않아서, 추후 BLIP 논문도 리뷰해볼 예정이다.

 

[논문 링크]

https://arxiv.org/pdf/2305.14720.pdf

 


Pre-liminary


 

그래도 가볍게 알아보고 넘어가면 좋을 것 같아서 정리해보았다.

 

BLIP-2 : Vision-language interaction을 위한 deep learning model

  • image와 text간의 상호작용을 이해하고, 이를 바탕으로 vision-language task 수행
  • multimodal 모델이며 language-vision encoder를 통해 이미지와 텍스트를 각각 처리하는 별도의 encoder를 사용
  • zero-shot / transfer learning에 용이
  • 응용 분야
    • image captioning : 이미지 내용을 자연어로 설명
    • Visual QA
    • Text-based image retrieval : 텍스트 설명과 일치하는 이미지 찾기
    • Subject-drive image generation : 특정 주제에 대한 텍스트 설명을 바탕으로 관련 이미지 생성 / 수정

궁금한 점 (이는 논문 스터디가 끝나고 궁금했던 질문에 대해서 물어본 것이다. 논문 읽기 전에 discussion을 읽고 넘어가면 꽤 도움이 될 것 같아서 미리 첨부하고자 한다.)

  • 그러면 image editing이랑 비슷한 분야인가?
    • subject-driven generation에서 subject의 외형을 유지하며 다양한 이미지를 만드는 건, 우리가 image중에서 수정하고 싶은 부분에 대해서만 image를 수정한다는 건 수정하고 싶지 않은 부분은 유지하면서 수정하고 싶은 부분에 대해 다양한 변화를 주는거니까?
  • multimodal encoder에 들어가는 query는 정확하게 어떤 정보일까?
    • learnable한 parameter
  • visual representation을 diffusion model이 활용하고, subject representation을 diffusion model 안에 넣는 것 같은데 그 2개의 차이점이 뭘까?
    • subject representation : 편집하고자 하는 subject에 대한 representation
    • visual representation : image 전체의 representation


Abstract


text prompt 기반으로 input subject에 맞는 새로운 renditions을 제시하는 모델들은 일반적으로 fine-tuning 시간이 길고 주제에 대한 fidelity를 유지하는 것이 힘들다.

  • fidelity를 유지하는 것이 힘들다 → text embedding만 고려하고 input image를 고려하지 않다보니, subject에 대한 fidelity를 유지하는 게 힘듦

따라서 multimodal control을 지원하는 새로운 subject-drive image generation 모델인 BLIP-Diffusion 소개

  • BLIP-2로 text와 일치하는 (align) visual representation 생성
  • 생성된 representation을 활용하여 새로운 subject rendition을 생성하는 diffusion model 개발
  • ControlNet과 같은 prompt-to-prompt 기술과 자유롭게 결합 가능

❗ subject rendition : 텍스트로 설명된 subject에 맞게 이미지를 생성하는 것, 따라서 subject에 대한 설명에 대한 일관성을 유지하면서 다양한 이미지를 생성하는 것이 관건


Introduction


 

text-to-image model을 응용하는 분야 중 하나는 입력된 subject의 외형을 그대로 보존하면서 새로운 rendition을 생성하는 ‘subject-drive generation’이다.

‘subject-driven generation’의 일반적인 접근 방법은 subject의 visual 정보를 text embedding space로 변환하는 것이다.

  • 정확하게 말하자면, pretrained text-to-image model을 사용하여 placeholder text embedding을 최적화 → subject images의 set를 재구성
  • 이 후, embedding을 자연어 prompt로 구성하여 새로운 subject rendition을 생성

하지만 이 단계에서 굉장히 긴 fine-tuning 단계 (수백에서 수천) 를 반복하면서 다양한 주제로 효율적인 확장을 하는 것을 반복

이런 점이 text-image 모델에서 text와 image를 동시에 control input으로 사용하지 않는다.

따라서, 이러한 한계를 극복하기 위해 zero-shot / few-shot step fine-tuning을 갖춘 subject-driven text-to-image generation model, BLIP-diffusion을 제안한다.

BLIP-diffusion = vision-language encoder (ex.BLIP-2) + latent diffusion model (ex.stable diffusion)

  • BLIP-2 : image와 text를 받아서 text와 일치하는 subject representation 출력
  • subject representation → prompt embedding
  • latent diffusion model : 생성된 prompt로 image 생성 및 편집

또한, 2가지 pre-training 전략을 제안

  • 첫 번째 pre-training stage
    • multimodal representation learning → BLIP-2가 text와 일치하는 representation 생성하도록 만듦
    • input image + class label → BLIP-2에 입력 → multimodal embedding (=subject representation)
    • 이는 BLIP-diffusion의 첫 번째 단계를 수행하기 위함
  • 두 번째 pre-training stage
    • input visual features를 기반으로 새로운 subject renditions 생성
    • prompt-to-prompt 접근 방식으로 image editing도 가
    • 이는 BLIP-diffusion의 2,3번째 단계를 수행하기 위함


3. Method


BLIP-diffusion을 제안하며 아래 그림과 같은 two-stage pretraining 전략을 제시

pre-training 단계

  • 첫 번째 : multimodal representation 학습 단계
    • text에 맞는 image representation 생성
  • 두 번째 : subject representation 학습 단계
    • text와 subject representation을 통해 diffusion model로 새로운 subject rendition 생성

Q former : image로부터 text와 연관된 정보를 추출하는 구조

3.1 Multimodal Representation Learning with BLIP-2

  • latent diffusion model : stable diffusion 사용
  • CLIP text encoder 기반으로 prompt embedding 생성

첫 번째 pretraining stage에 대한 내용 (Figure 2.a)

  • image encoder & multimodal encoder (Q-Former)
    • multimodal encoder : 고정된 수의 학습 가능한 쿼리와 input text 받음
      • query token은 self attention으로 input text와 상호작용
      • query token은 image feature와는 cross-attention으로 상호작용하여 text에 맞는 image feature를 출력

학습에 사용되는 loss

  • Image-text contrastive learning (ITC) : image와 text간의 loss
  • Image-grounded text generation (ITG) : input image에 맞는 text를 generation할 수 있도록.
  • Image-text matching (ITM) : 가지고 있는 모든 정보를 통해 text와 image 사이의 self-attention mask를 사용하여 matching 정도를 확인

3.2 Subject Representation Learning with Stable Diffusion

BLIP-2를 거치면 text에 맞는 visual representation을 얻는다.

이 단계에서는 얻은 visual representation을 diffusion model이 활용하여 새로운 subject renditions을 생성하는 것이 목표이다.

여기서, subject representation을 diffusion model에 입력할 때, 2가지를 고려해야 한다.

  • subject representation이 text prompt와 잘 상호작용 되어야 한다. (well coordinate)
  • 기본 diffusion model은 그대로 유지가 되어야만 원래 모델 위에 새롭게 구축된 기술을 활용할 수 있다.

Model architecture → 조금 더 자세하게 들을 것

  1. BLIP-2 multimodal encoder의 output → diffusion text encoder의 input 단에 연결
  2. multimodal encoder로부터 subject representation 생성
  3. subject representation을 GELU layer 2개로 통과하는 feedforward layer를 사용하여 변환
  4. 변환된 feature → text prompt token embedding
  5. text prompt token embedding + subject embedding → CLIP text encoder를 통과
    1. 이 때, 정해진 template에 따라 prompt 생성
    2. 이렇게 하면 주제와 text와 상관없는 이미지 생성을 방지할 수 있음.

Subject-generic Pre-training with Prompted Context Generation

input image → generic subjects을 위해서 multimodal encoder의 input과 diffusion model의 output을 모두 동일한 이미지로 사용하는 것

하지만 이는 image의 background에 의해 잘 작동되지 않으며 모델이 output image를 input image와 똑같이 생성하여 text prompt를 반영 못할 수도 있음 + 일반적인 주제 확장이 어려움

→ 따라서 ‘prompted context generation’을 제안

  • 이는 subject image에 무작위로 배경을 합성하여 input-target training pair를 만들어서 제작
  • 합성된 이미지 + text prompt → original subject image 생성을 목표

detail

  • subject가 포함된 image가 주어지면 image와 subject의 category text에 대한 confidence threshold를 가진 CLIPSeq에 입력
  • 높은 confidence를 가진 segmentation map을 foreground, 낮은 confidence를 가진 segmentation map은 uncertain region으로, 나머지는 known background
    • confidence가 높으면 foreground (집중), 낮은 confidence는 변경의 여지가 남아있는 지역으로, 그 외의 지역들은 학습된 데이터 내에서의 배경으로 하여 trimap 구성
  • tripmap이 주어지면 closed-form matting으로 subject를 추출
  • alpha blending을 통해 subject에 무작위 background를 구성 → 이미지 합성
  • 합성된 이미지를 input + 원래 subject image를 output (target) → training pair dataset

text prompt를 사용하는 동안, subject prompt를 15%의 확률로 random하게 삭제하는 것이 이득이 더 크다는 것을 발견

3.3 Fine-tuning and Controllable Inference

pretrained subject representation → zero-shot generation + efficient fine-tuning for specific subject

기본적으로 diffusion model을 사용하기 때문에 high quality 보장

fine-tuning 후에 ControlNet의 prompt-to-prompt image editing 기술로 BLIP-diffusion 기능 수행

다음 내용들은 특정 subject에 대한 fine-tuning 단계를 설명

Subject-specific Fine-tuning and Inference

사전 학습된 일반화된 subject representation은 매우 개인화된 (사용자에 맞춰진) subject에 대해서도 fine-tuning을 가능하게 만든다.

  1. few subject image (pre-trained) + subject category text (주제를 설명하는 text) → multimodal encoder → individual subject representation
    1. 여러 개의 subject representation을 개별적으로 추출
  2. 모든 subject image의 평균 image를 사용 → subject prompt embedding 초기화
  3. subject prompt embedding & mean subject embedding → diffusion model을 fine-tuning
    1. 여기서 diffusion model의 text encoder를 고정함으로써 overfitting 방지
      1. 아마 text encoder가 고정되지 않는다면 prompt embedding에 과적합될 가능성이 생김

  • ControlNet의 U-Net을 BLIP-diffusion의 U-Net 연결
    • 모델은 subject 정보 뿐만 아니라 edge map, depth map과 같은 구조적인 정보도 input으로 받을 수 있다.

Subject-drive Editing with Attention Control

multimodal controlled generation을 위해 subject prompt embedding과 text prompt embedding 결합

Figure 4에서 모델이 subject visual representation으로 original image를 편집하는 것이 가능한 것을 확인할 수 있다.

그 말은, original image의 생성 과정을 알려져 있거나 혹은 실제 이미지에 대해서 inversion을 통해 유도될 수 있음을 가정

  • original image의 생성 과정을 알고 있으면 diffusion model 등으로 역변환 가능

How?

  1. 편집할 text token을 지정한다.
  2. 지정된 token의 cross-attention map을 활용하여 편집할 region을 찾는다.
  3. 편집하지 않을 region은 정보 보존을 위해서 새로운 attention map이 생성될 동안, original generation의 attention map을 그대로 유지한다.
  4. 추출된 editing mask로 각 단계 별로 denoising latent variable을 혼합
    1. 이로 인해 편집하지 않을 region은 원래 (original) 이미지에서 그대로 보존되어 나오고, 편집할 지역은 subject-drive generation에 나온다.

⇒ cross-attention으로 편집할 특정 부분 (→editing mask)을 찾고 편집하지 않을 부분은 original image를 그대로 유지함으로써 의미 있는 편집된 이미지를 얻을 수 있다.

 


4. Experiments


zero-shot으로 subject driven generation

  • 각 subject text에 대한 image feature가 잘 유지된 채, 여러 image가 generation
  • cat + toy : 고양이 모양의 toy로 잘 generation

Few-step Fine-tuned -

  • text 일부를 추가해서 새로운 image editing

이 외에도 texture를 수정한다거나 악세사리만 편집할 수 있으며 subject를 유지하면서 image editing도 가능

다른 baseline보다 훨씬 적은 step으로도 높은 퀄리티의 image를 generation이 가능하다.

subject와 text의 alignment를 판단

  • subject가 상당히 잘 align 되어 있음을 확인

아쉬운 점 : overfitting이 될 가능성이 높아서 step수를 작게 수정한다는 점 외에는 다른 training 방법을 제시하지 않았음.

 


Limitations and Failure Cases


  • text에 맞지 않는 context를 부여하면 실패
  • pre-trained diffusion model 자체가 완벽하지 않아서 생기는 문제점들을 가지고 있음


마치며


 

BLIP 모델에 대해서 조금 더 공부한 상태였다면, 이해하는 데에 더 빨랐을텐데 라는 아쉬움이 있었다. 하지만 여러 모델들을 응용하는 과정에 대해서 조금 더 깊게 이해할 수 있었고, 나도 기본을 조금 더 탄탄하게 쌓아서 이런 연구들을 하루빨리 시작해보고 싶다는 생각을 하게 되었다.

 

파이팅!

 

 

728x90
반응형