Riffusion(3)

City_Duck·2023년 2월 28일
0

Riffusion

목록 보기
5/6

Diffusers

🤗 Diffusers provides pretrained diffusion models across multiple modalities, such as vision and audio, and serves as a modular toolbox for inference and training of diffusion models.

Diffusers는 HuggingFace에서 제공하는 손쉬운 Diffusion 라이브러리이다.
해당 라이브러리는 다음과 같은 기능을 제공한다.

  • 단 몇줄의 코드로 SOTA Diffusion 파이프라인을 제공한다.
  • 다양한 노이즈 스케줄러를 제공한다. 속도와 퀄리티는 trade off 관계
  • UNet과 같은 다양한 모델을 제공한다.
  • 다양한 Traning Example을 볼 수 있다.

Diffusesrs에 대한 example은 다음 링크에서 확인할 수 있다.

Diffusers를 대표하는 기능은 Stable Diffusion이다.

Stable Diffusion is fully compatible with diffusers!

Stable Diffusion이란 CompVis, Stability AI, LAION and RunwayML에서 만든 text-to-image latent diffusion 모델이며 LAION-5B database의 512x512 images를 학습하였다.
해당 모델은 123M frozen CLIP Vit-L/14 text encoder와 860M UNet을 사용하였으며, 4GB VRAM으로도 돌릴 수 있는 가벼운 모델이다.

Text-to-Image generation with Stable Diffusion

import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
pipe = pipe.to("cuda")

prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]  

다음과 같은 간단한 코드로 Stable Diffusion을 사용 가능하다.

스케줄러 변경을 원한다면 다음과 같은 간단한 코드를 추가함으로써 가능하다.

from diffusers import LMSDiscreteScheduler

pipe.scheduler = LMSDiscreteScheduler.from_config(pipe.scheduler.config)

prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]  
    
image.save("astronaut_rides_horse.png")

더욱 자세한 사용방법은 Diffusers 해당 사이트에서 확인 가능하다.

Fine-Tuning Stable Diffusion

Stable Diffusion Fine-tuning을 위해 Diffusers는 다음과 같은 기능을 제공한다.

  • Textual Inversion : text encoder에 새로운 words를 적은 데이터셋으로 학습할 수 있다. 이는 Textual Inversion 페이지에서 확인할 수 있다.
  • Dreambooth : UNet을 fine-tunes 할 수 있는 방법이다. 이는 Dreambooth 페이지에서 확인할 수 있다.
  • Full Stable Diffusion fine-tuning : 충분한 데이터셋이 있다면 Full fine-tuning도 가능하다. 이에 대한 예시는 pokemon 페이지에서 확인할 수 있다.

In the works

For the first release, 🤗 Diffusers focuses on text-to-image diffusion techniques. However, diffusers can be used for much more than that! Over the upcoming releases, we'll be focusing on

  • Diffusers for audio
  • Diffusers for reinforcement learning (initial work happening in #105).
  • Diffusers for video generation
  • Diffusers for molecule generation (initial work happening in #54)

A few pipeline components are already being worked on, namely:

  • BDDMPipeline for spectrogram-to-sound vocoding
  • GLIDEPipeline to support OpenAI's GLIDE model
  • Grad-TTS for text to audio generation / conditional audio generation

또한 Diffusers/examples에는 다양한 Diffusers 예시들이 존재한다.
이를 통해 간편하게 Diffusion Model을 적용할 수 있다.


HuggingFace Diffusers

profile
AI 새싹

0개의 댓글