mirror of
https://github.com/wassname/denoising-diffusion-pytorch.git
synced 2026-09-10 12:01:08 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42158d6248 | ||
|
|
44f95e2e9d | ||
|
|
d9275a744c |
@@ -10,6 +10,8 @@ Youtube AI Educators - <a href="https://www.youtube.com/watch?v=W-O7AZNzbzQ">Yan
|
||||
|
||||
<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>
|
||||
|
||||
<img src="./images/sample.png" width="500px"><img>
|
||||
|
||||
[](https://badge.fury.io/py/denoising-diffusion-pytorch)
|
||||
|
||||
@@ -97,16 +97,11 @@ class WeightStandardizedConv2d(nn.Conv2d):
|
||||
eps = 1e-5 if x.dtype == torch.float32 else 1e-3
|
||||
|
||||
weight = self.weight
|
||||
flattened_weights = rearrange(weight, 'o ... -> o (...)')
|
||||
|
||||
mean = reduce(weight, 'o ... -> o 1 1 1', 'mean')
|
||||
var = reduce(weight, 'o ... -> o 1 1 1', partial(torch.var, unbiased = False))
|
||||
normalized_weight = (weight - mean) * (var + eps).rsqrt()
|
||||
|
||||
var = torch.var(flattened_weights, dim = -1, unbiased = False)
|
||||
var = rearrange(var, 'o -> o 1 1 1')
|
||||
|
||||
weight = (weight - mean) * (var + eps).rsqrt()
|
||||
|
||||
return F.conv2d(x, weight, self.bias, self.stride, self.padding, self.dilation, self.groups)
|
||||
return F.conv2d(x, normalized_weight, self.bias, self.stride, self.padding, self.dilation, self.groups)
|
||||
|
||||
class LayerNorm(nn.Module):
|
||||
def __init__(self, dim):
|
||||
@@ -432,6 +427,7 @@ class GaussianDiffusion(nn.Module):
|
||||
):
|
||||
super().__init__()
|
||||
assert not (type(self) == GaussianDiffusion and model.channels != model.out_dim)
|
||||
assert not model.learned_sinusoidal_cond
|
||||
|
||||
self.model = model
|
||||
self.channels = self.model.channels
|
||||
@@ -574,15 +570,15 @@ class GaussianDiffusion(nn.Module):
|
||||
|
||||
times = torch.linspace(0., total_timesteps, steps = sampling_timesteps + 2)[:-1]
|
||||
times = list(reversed(times.int().tolist()))
|
||||
time_pairs = list(zip(times[:-1], times[1:]))
|
||||
time_pairs = list(filter(lambda a: a[0] > a[1], zip(times[:-1], times[1:])))
|
||||
|
||||
img = torch.randn(shape, device = device)
|
||||
|
||||
x_start = None
|
||||
|
||||
for time, time_next in tqdm(time_pairs, desc = 'sampling loop time step'):
|
||||
alpha = self.alphas_cumprod_prev[time]
|
||||
alpha_next = self.alphas_cumprod_prev[time_next]
|
||||
alpha = self.alphas_cumprod[time]
|
||||
alpha_next = self.alphas_cumprod[time_next]
|
||||
|
||||
time_cond = torch.full((batch,), time, device = device, dtype = torch.long)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
||||
setup(
|
||||
name = 'denoising-diffusion-pytorch',
|
||||
packages = find_packages(),
|
||||
version = '0.27.3',
|
||||
version = '0.27.5',
|
||||
license='MIT',
|
||||
description = 'Denoising Diffusion Probabilistic Models - Pytorch',
|
||||
author = 'Phil Wang',
|
||||
|
||||
Reference in New Issue
Block a user