mirror of
https://github.com/wassname/denoising-diffusion-pytorch.git
synced 2026-09-11 12:11:43 +08:00
small helper fn to make sampling more clear
This commit is contained in:
@@ -34,8 +34,8 @@ loss = diffusion(training_images)
|
|||||||
loss.backward()
|
loss.backward()
|
||||||
# after a lot of training
|
# after a lot of training
|
||||||
|
|
||||||
sampled_images = diffusion.p_sample_loop((1, 3, 128, 128))
|
sampled_images = diffusion.sample(128, batch_size = 4)
|
||||||
sampled_images.shape # (1, 3, 128, 128)
|
sampled_images.shape # (4, 3, 128, 128)
|
||||||
```
|
```
|
||||||
|
|
||||||
Or, if you simply want to pass in a folder name and the desired image dimensions, you can use the `Trainer` class to easily train a model.
|
Or, if you simply want to pass in a folder name and the desired image dimensions, you can use the `Trainer` class to easily train a model.
|
||||||
|
|||||||
@@ -309,6 +309,10 @@ class GaussianDiffusion(nn.Module):
|
|||||||
img = self.p_sample(img, torch.full((b,), i, device=device, dtype=torch.long))
|
img = self.p_sample(img, torch.full((b,), i, device=device, dtype=torch.long))
|
||||||
return img
|
return img
|
||||||
|
|
||||||
|
@torch.no_grad()
|
||||||
|
def sample(self, image_size, batch_size = 16):
|
||||||
|
return self.p_sample_loop((16, 3, image_size, image_size))
|
||||||
|
|
||||||
def q_sample(self, x_start, t, noise=None):
|
def q_sample(self, x_start, t, noise=None):
|
||||||
noise = default(noise, lambda: torch.randn_like(x_start))
|
noise = default(noise, lambda: torch.randn_like(x_start))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user