dmarx / notebooks

misc notebooks i wanted to put in tracking
17 stars 2 forks source link

[klmc2] init image #6

Closed dmarx closed 1 year ago

dmarx commented 1 year ago
from PIL import Image
from pathlib import Path

if Path(init_image).exists():
  init_im_pil = Image.open(init_image)

#init_im_pil.size
import numpy as np

x_pil = init_im_pil.resize([512,512])
x_np = np.array(x_pil.convert('RGB')).astype(np.float16) / 255.0

#image = np.array(image).astype(np.float16) / 255.0
x = x_np[None].transpose(0, 3, 1, 2)
x = 2.*x - 1.
x = torch.from_numpy(x).to('cuda')
x = sd_model.get_first_stage_encoding(sd_model.encode_first_stage(x))