Commit 383dc795 authored by anton-l's avatar anton-l
Browse files

glide is alive!

parent d754ce5f
...@@ -124,6 +124,7 @@ class GLIDE(DiffusionPipeline): ...@@ -124,6 +124,7 @@ class GLIDE(DiffusionPipeline):
- _extract_into_tensor(self.noise_scheduler.sqrt_recipm1_alphas_cumprod, t, x_t.shape) * eps - _extract_into_tensor(self.noise_scheduler.sqrt_recipm1_alphas_cumprod, t, x_t.shape) * eps
) )
@torch.no_grad()
def __call__(self, prompt, generator=None, torch_device=None): def __call__(self, prompt, generator=None, torch_device=None):
torch_device = "cuda" if torch.cuda.is_available() else "cpu" torch_device = "cuda" if torch.cuda.is_available() else "cpu"
...@@ -164,4 +165,6 @@ class GLIDE(DiffusionPipeline): ...@@ -164,4 +165,6 @@ class GLIDE(DiffusionPipeline):
nonzero_mask = (t != 0).float().view(-1, *([1] * (len(image.shape) - 1))) # no noise when t == 0 nonzero_mask = (t != 0).float().view(-1, *([1] * (len(image.shape) - 1))) # no noise when t == 0
image = mean + nonzero_mask * torch.exp(0.5 * log_variance) * noise image = mean + nonzero_mask * torch.exp(0.5 * log_variance) * noise
image = image[0].permute(1, 2, 0)
return image return image
import torch import torch
from modeling_glide import GLIDE from modeling_glide import GLIDE
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rcParams['interactive'] = True
generator = torch.Generator() generator = torch.Generator()
...@@ -10,5 +13,8 @@ generator = generator.manual_seed(0) ...@@ -10,5 +13,8 @@ generator = generator.manual_seed(0)
pipeline = GLIDE.from_pretrained("fusing/glide-base") pipeline = GLIDE.from_pretrained("fusing/glide-base")
img = pipeline("an oil painting of a corgi", generator) img = pipeline("an oil painting of a corgi", generator)
img = ((img + 1)*127.5).round().clamp(0, 255).to(torch.uint8).cpu().numpy()
print(img) plt.figure(figsize=(8, 8))
plt.imshow(img)
plt.show()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment