mirror of
https://github.com/wassname/denoising-diffusion-pytorch.git
synced 2026-09-10 12:01:08 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f762d33c17 | ||
|
|
dfbafee555 | ||
|
|
40dd8ba1de | ||
|
|
2ac3f94a80 | ||
|
|
98f2eeac35 | ||
|
|
6e8a0f2082 |
@@ -8,6 +8,8 @@ This implementation was transcribed from the official Tensorflow version <a href
|
||||
|
||||
Youtube AI Educators - <a href="https://www.youtube.com/watch?v=W-O7AZNzbzQ">Yannic Kilcher</a> | <a href="https://www.youtube.com/watch?v=344w5h24-h8">AI Coffeebreak with Letitia</a> | <a href="https://www.youtube.com/watch?v=HoKDTa5jHvg">Outlier</a>
|
||||
|
||||
<a href="https://github.com/yiyixuxu/denoising-diffusion-flax">Flax implementation</a> from <a href="https://github.com/yiyixuxu">YiYi Xu</a>
|
||||
|
||||
<a href="https://huggingface.co/blog/annotated-diffusion">Annotated code</a> by Research Scientists / Engineers from <a href="https://huggingface.co/">🤗 Huggingface</a>
|
||||
|
||||
Update: Turns out none of the technicalities really matters at all | <a href="https://arxiv.org/abs/2208.09392">"Cold Diffusion" paper</a>
|
||||
|
||||
@@ -56,14 +56,11 @@ def num_to_groups(num, divisor):
|
||||
arr.append(remainder)
|
||||
return arr
|
||||
|
||||
def convert_image_to(img_type, image):
|
||||
def convert_image_to_fn(img_type, image):
|
||||
if image.mode != img_type:
|
||||
return image.convert(img_type)
|
||||
return image
|
||||
|
||||
def l2norm(t):
|
||||
return F.normalize(t, dim = -1)
|
||||
|
||||
# normalization functions
|
||||
|
||||
def normalize_to_neg_one_to_one(img):
|
||||
@@ -239,9 +236,10 @@ class LinearAttention(nn.Module):
|
||||
class Attention(nn.Module):
|
||||
def __init__(self, dim, heads = 4, dim_head = 32, scale = 10):
|
||||
super().__init__()
|
||||
self.scale = scale
|
||||
self.scale = dim_head ** -0.5
|
||||
self.heads = heads
|
||||
hidden_dim = dim_head * heads
|
||||
|
||||
self.to_qkv = nn.Conv2d(dim, hidden_dim * 3, 1, bias = False)
|
||||
self.to_out = nn.Conv2d(hidden_dim, dim, 1)
|
||||
|
||||
@@ -250,11 +248,12 @@ class Attention(nn.Module):
|
||||
qkv = self.to_qkv(x).chunk(3, dim = 1)
|
||||
q, k, v = map(lambda t: rearrange(t, 'b (h c) x y -> b h c (x y)', h = self.heads), qkv)
|
||||
|
||||
q, k = map(l2norm, (q, k))
|
||||
q = q * self.scale
|
||||
|
||||
sim = einsum('b h d i, b h d j -> b h i j', q, k) * self.scale
|
||||
sim = einsum('b h d i, b h d j -> b h i j', q, k)
|
||||
attn = sim.softmax(dim = -1)
|
||||
out = einsum('b h i j, b h d j -> b h i d', attn, v)
|
||||
|
||||
out = rearrange(out, 'b h (x y) d -> b (h d) x y', x = h, y = w)
|
||||
return self.to_out(out)
|
||||
|
||||
@@ -704,7 +703,7 @@ class Dataset(Dataset):
|
||||
self.image_size = image_size
|
||||
self.paths = [p for ext in exts for p in Path(f'{folder}').glob(f'**/*.{ext}')]
|
||||
|
||||
maybe_convert_fn = partial(convert_image_to, convert_image_to) if exists(convert_image_to) else nn.Identity()
|
||||
maybe_convert_fn = partial(convert_image_to_fn, convert_image_to) if exists(convert_image_to) else nn.Identity()
|
||||
|
||||
self.transform = T.Compose([
|
||||
T.Lambda(maybe_convert_fn),
|
||||
@@ -845,6 +844,7 @@ class Trainer(object):
|
||||
|
||||
self.accelerator.backward(loss)
|
||||
|
||||
accelerator.clip_grad_norm_(self.model.parameters(), 1.0)
|
||||
pbar.set_description(f'loss: {total_loss:.4f}')
|
||||
|
||||
accelerator.wait_for_everyone()
|
||||
|
||||
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
||||
setup(
|
||||
name = 'denoising-diffusion-pytorch',
|
||||
packages = find_packages(),
|
||||
version = '0.27.10',
|
||||
version = '0.28.0',
|
||||
license='MIT',
|
||||
description = 'Denoising Diffusion Probabilistic Models - Pytorch',
|
||||
author = 'Phil Wang',
|
||||
|
||||
Reference in New Issue
Block a user