집컴이 쓰레기라 Colab 씀.
깃허브 가져와서 디렉토리 바꿔주고
!git clone https://github.com/castorini/daam.git
%cd /content/daam
라이브러리 설치해주고
!pip install transformers
!pip install diffusers
깃허브에 있는 코드 그대로 돌렸는데...
from daam import trace, set_seed
from diffusers import StableDiffusionPipeline
from matplotlib import pyplot as plt
import torch
model_id = 'stabilityai/stable-diffusion-2-base'
device = 'cuda'
pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
pipe = pipe.to(device)
prompt = 'A Little Cabin in the City of Cyberpunk'
gen = set_seed(0) # for reproducibility
with torch.cuda.amp.autocast(dtype=torch.float16), torch.no_grad():
with trace(pipe) as tc:
out = pipe(prompt, num_inference_steps=30, generator=gen)
heat_map = tc.compute_global_heat_map()
heat_map = heat_map.compute_word_heat_map('dog')
heat_map.plot_overlay(out.images[0])
plt.show()
Hugging face 토큰이 필요하다고 해서
OSError: Token is required (`token=True`), but no token found. You need to provide a token or be logged in to Hugging Face with `huggingface-cli login` or `huggingface_hub.login`. See https://huggingface.co/settings/tokens.
토큰 등록 해주고
근데 또 에러가 뜨면서 accelerate가 필요하대..
Cannot initialize model with low cpu memory usage because `accelerate` was not found in the environment. Defaulting to `low_cpu_mem_usage=False`. It is strongly recommended to install `accelerate` for faster and less memory-intense model loading.
깔아주고...
!pip install accelerate
근데 또 안됨...
trace를 뺐을 때는 첫 줄을 넘어가는 것을 보면 diffusionpipeline의 문제는 아니고...
그냥 깃허브 가져올 때 requirements를 설치하니깐 됐음... 그냥 버전 호환 문제였던 듯... 진짜 기본적인건데...
!git clone https://github.com/castorini/daam && pip install -e daam
%cd /content/daam
아무튼 이제 써보자.
단어를 하나씩 뽑아 볼거니깐 저기서 멈춰주고
prompt = 'A small cabin in the city'
gen = set_seed(0) # for reproducibility
with torch.cuda.amp.autocast(dtype=torch.float16), torch.no_grad():
with trace(pipe) as tc:
out = pipe(prompt, num_inference_steps=30, generator=gen)
heat_map = tc.compute_global_heat_map()
함수를 하나 만들어서 단어를 하나씩 뽑아보자.
def heat_map_plot(global_heat_map, word):
heat_map = global_heat_map.compute_word_heat_map(word)
heat_map.plot_overlay(out.images[0])
plt.show()
근데 내가 원했던 건 영화 up처럼 도시 속에 조그만 오두막이 있는 그림을 원했는데...
구글에 A small cabin in the city를 쳐보니까 이유를 알았다...
'Deep Learning > Diffusion' 카테고리의 다른 글
Stable Diffusion, SDXL U-Net Architecture 살펴보기 (2) | 2023.10.05 |
---|---|
DiffStyler 써보기 (0) | 2023.01.17 |
Paint by Example 써보기 (1) | 2023.01.13 |