Riffusion(2)

City_Duck·2023년 2월 28일
1

Riffusion

목록 보기
4/6

High-Resolution Image Synthesis with Latent Diffusion Models

"However, since these models typically operate directly in pixel space, optimization of powerful DMs often consumes hundreds of GPU days and inference is expensive due to sequential evaluations."

  • Latent Space가 아닌 Pixel space에 직접적으로 동작을 하면 리소스가 너무 많이 요구된다.

"In contrast to previous work, training diffusion models on such a representation allows for the first time to reach a near-optimal point between complexity reduction and detail preservation, greatly boosting visual fidelity."

  • 해당 방법은 complexity reduction and detail preservation, greatly boosting visual fidelity와 같은 장점을 얻을 수 있다.

By introducing cross-attention layers into the model architecture, ...

  • Cross-attention을 해당 모델에 적용하면서 powerful and flexible한 생성기를 얻을 수 있었다.

Latent Diffusion의 경우 다른 모델들과 다르게 요구 리소스가 대폭 줄어들었다.
이는 Pixel Space가 아닌 Latent Space에서 동작을 하였기 때문이다.
Latent Space에서 Diffusion을 적용한 방법은 다음과 같다.

먼저 미리 학습한 AE의 Encoder를 통해 고차원의 데이터를 저차원 space(latent space)로 맵핑시킨다.

이에 latent space에 들어가는 변수를 latent variable이라 하며 Decoder에서는 latent variable을 받아 이미지를 복원시킨다.

해당 모델에서 사용된 AE의 매커니즘은 VAE의 매커니즘(lower bound)과 비슷하다.

참고 : Why diffusion model always use U-Net?
또한 UNet을 사용하는데 이는 UNet의 Inductive bias를 활용하기 위해서라고 적혀있는데 이는 업샘플링을 이야기하는 것으로 추측한다.

자세한 작동 과정은 illustrated-stable-diffusion 해당 블로그에서 알기 쉽게 설명되어있다.

정리하자면

  1. CLIP 인코더를 통해 Text Prompt가 text embedding으로 변환됨
  2. 해당 임베딩은 UNet으로 전달, UNet은 Noise Predictor 역할을 하며 주어진 텍스트에 조건화 되어 random latent vector를 반복적으로 Denoising을 한다.
  3. UNet의 결과(latent variable)을 Decoder를 통해 이미지로 변환

이는 다음과 같이 해석할 수 있다.

  • 가우시안 분포의 Random latent vector를 사용하여 결과의 다양성을 보장
  • 노이즈로 오염된 이미지를 QQ, 텍스트를 K,VK,V로 두어 Cross-Attention을 수행
  • UNet을 사용하여 UNet 구조의 inductive bias를 사용
  • Latent Space에서 연산을 수행하기에 Computing Cost를 줄임

해당 Latent Diffusion 모델을 기반으로 StabilityAI에서 자사 데이터를 기반으로 Stable Diffusion 모델이 출시되었다.

Riffusion

앞서 언급한 Stable Diffusion 모델을 기반으로 스펙토그램을 학습한 모델이다.

"This is the v1.5 stable diffusion model with no modifications, just fine-tuned on images of spectrograms paired with text"

해당 모델은 오디오에 STFT(Short-time Fourier transform), Griffin-Lim, Mel scale을 적용하여 스펙토그램을 만들었고 이를 text와 함께 학습한 모델이다.

Image To Image

"With diffusion models, it is possible to condition their creations not only on a text prompt but also on other images"

Riffusion은 text prompt을 통한 condition 뿐만 아닌 image를 통한 condition을 지원한다.
해당 기능은 Seed Image를 통해 사용할 수 있다.

Looping and Interpolation

Riffusion 저자들은 짧은 음악이 아닌 "infinite AI-generated jams"을 원했다.
하지만 이에는 요구되는 resource가 상당히 크다. (A100 기준 30초 이상 inference가 힘듦)
그렇기에 저자들은 분할된 음악을 연결하는 방안을 고안했다.

"Our strategy is to pick one initial image and generate variations of it by running image-to-image generation with different seeds and prompts"

즉 하나의 초기 이미지(Seed Image)를 Prompt 혹은 seed를 통해 Image to Image를 수행하여 연결할 수 있는 비슷한 분위기의 음악을 생성하고자 하였다.

하지만 같은 시드와 프롬프트를 사용해도 멜로디와 분위기가 사뭇 다른 결과가 많이 발생하였고 이를 해결하기 위해 latent space에서 Interpolation을 시도하였고 결과는 성공적이였다.

그렇기에 이를 통해 typing to jazz와 같이 사뭇 다른 소리를 자연스럽게 연결시킬 수 있었다.

Prompt Guide

저자들은 다른 Diffusion 계열의 모델과 같이 해당 모델도 Prompt에 성능이 크게 좌우된다라고 명시하였다.

Prompt의 구성 요소로는 다음과 같다.

  • Seed image : 해당 Prompt를 기반으로 Image to Image를 수행한다, 시드 이미지에 따라 BPM과 전반적인 Vibe가 정해진다.
  • Denoising : 디폴트 값 0.75를 기준으로 높을수록 Seed Image와 다른 결과가 낮을 수록 Seed Image에 가까운 결과가 나온다.
  • Prompt : 악기와 장르를 Text Prompt로 넣어줄 수 있다. 또한 학습된 데이터가 아니더라도(악기 혹은 장르) text encoder인 CLIP Encoder가 similar semantic을 찾을 수 있기에 가능하다. 하지만 Seed Image와 BPM에 맞지 않는 Prompt가 들어가면 결과가 안좋을 수 있다.
  • Prompt Reweighting : Prompt에 있는 토큰의 영향력을 조절할 수 있다.
    • (vocals:1.2) -> Vocals 영향력 1.2배 강화
    • [vocals:1.2] -> Vocals 영향력 1.2배 약화

참고 : Stable Diffusion 논문 리뷰, Stable Diffusion이 대체 무엇일까?
출처 : Riffusion

profile
AI 새싹

0개의 댓글