mirror of
https://github.com/lucidrains/DALLE2-pytorch.git
synced 2026-02-23 21:24:37 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d82dff9c5 | ||
|
|
8bbc956ff1 | ||
|
|
22019fddeb | ||
|
|
6fb7e91343 |
@@ -1126,6 +1126,7 @@ For detailed information on training the diffusion prior, please refer to the [d
|
|||||||
- [x] add inpainting ability using resampler from repaint paper https://arxiv.org/abs/2201.09865
|
- [x] add inpainting ability using resampler from repaint paper https://arxiv.org/abs/2201.09865
|
||||||
- [x] add the final combination of upsample feature maps, used in unet squared, seems to have an effect in local experiments
|
- [x] add the final combination of upsample feature maps, used in unet squared, seems to have an effect in local experiments
|
||||||
- [ ] consider elucidated dalle2 https://arxiv.org/abs/2206.00364
|
- [ ] consider elucidated dalle2 https://arxiv.org/abs/2206.00364
|
||||||
|
- [ ] add simple outpainting, text-guided 2x size the image for starters
|
||||||
- [ ] interface out the vqgan-vae so a pretrained one can be pulled off the shelf to validate latent diffusion + DALL-E2
|
- [ ] interface out the vqgan-vae so a pretrained one can be pulled off the shelf to validate latent diffusion + DALL-E2
|
||||||
|
|
||||||
## Citations
|
## Citations
|
||||||
|
|||||||
@@ -1070,7 +1070,7 @@ class DiffusionPriorNetwork(nn.Module):
|
|||||||
|
|
||||||
null_text_embeds = self.null_text_embeds.to(text_embed.dtype)
|
null_text_embeds = self.null_text_embeds.to(text_embed.dtype)
|
||||||
|
|
||||||
text_embeds = torch.where(
|
text_embed = torch.where(
|
||||||
text_keep_mask,
|
text_keep_mask,
|
||||||
text_embed,
|
text_embed,
|
||||||
null_text_embeds
|
null_text_embeds
|
||||||
@@ -1259,7 +1259,7 @@ class DiffusionPrior(nn.Module):
|
|||||||
def p_sample_loop_ddim(self, shape, text_cond, *, timesteps, eta = 1., cond_scale = 1.):
|
def p_sample_loop_ddim(self, shape, text_cond, *, timesteps, eta = 1., cond_scale = 1.):
|
||||||
batch, device, alphas, total_timesteps = shape[0], self.device, self.noise_scheduler.alphas_cumprod_prev, self.noise_scheduler.num_timesteps
|
batch, device, alphas, total_timesteps = shape[0], self.device, self.noise_scheduler.alphas_cumprod_prev, self.noise_scheduler.num_timesteps
|
||||||
|
|
||||||
times = torch.linspace(0., total_timesteps, steps = timesteps + 2)[:-1]
|
times = torch.linspace(-1., total_timesteps, steps = timesteps + 1)[:-1]
|
||||||
|
|
||||||
times = list(reversed(times.int().tolist()))
|
times = list(reversed(times.int().tolist()))
|
||||||
time_pairs = list(zip(times[:-1], times[1:]))
|
time_pairs = list(zip(times[:-1], times[1:]))
|
||||||
@@ -1281,12 +1281,14 @@ class DiffusionPrior(nn.Module):
|
|||||||
|
|
||||||
pred = self.net.forward_with_cond_scale(image_embed, time_cond, self_cond = self_cond, cond_scale = cond_scale, **text_cond)
|
pred = self.net.forward_with_cond_scale(image_embed, time_cond, self_cond = self_cond, cond_scale = cond_scale, **text_cond)
|
||||||
|
|
||||||
|
# derive x0
|
||||||
|
|
||||||
if self.predict_x_start:
|
if self.predict_x_start:
|
||||||
x_start = pred
|
x_start = pred
|
||||||
pred_noise = self.noise_scheduler.predict_noise_from_start(image_embed, t = time_cond, x0 = pred)
|
|
||||||
else:
|
else:
|
||||||
x_start = self.noise_scheduler.predict_start_from_noise(image_embed, t = time_cond, noise = pred)
|
x_start = self.noise_scheduler.predict_start_from_noise(image_embed, t = time_cond, noise = pred_noise)
|
||||||
pred_noise = pred
|
|
||||||
|
# clip x0 before maybe predicting noise
|
||||||
|
|
||||||
if not self.predict_x_start:
|
if not self.predict_x_start:
|
||||||
x_start.clamp_(-1., 1.)
|
x_start.clamp_(-1., 1.)
|
||||||
@@ -1294,6 +1296,17 @@ class DiffusionPrior(nn.Module):
|
|||||||
if self.predict_x_start and self.sampling_clamp_l2norm:
|
if self.predict_x_start and self.sampling_clamp_l2norm:
|
||||||
x_start = self.l2norm_clamp_embed(x_start)
|
x_start = self.l2norm_clamp_embed(x_start)
|
||||||
|
|
||||||
|
# predict noise
|
||||||
|
|
||||||
|
if self.predict_x_start:
|
||||||
|
pred_noise = self.noise_scheduler.predict_noise_from_start(image_embed, t = time_cond, x0 = x_start)
|
||||||
|
else:
|
||||||
|
pred_noise = pred
|
||||||
|
|
||||||
|
if time_next < 0:
|
||||||
|
image_embed = x_start
|
||||||
|
continue
|
||||||
|
|
||||||
c1 = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt()
|
c1 = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt()
|
||||||
c2 = ((1 - alpha_next) - torch.square(c1)).sqrt()
|
c2 = ((1 - alpha_next) - torch.square(c1)).sqrt()
|
||||||
noise = torch.randn_like(image_embed) if time_next > 0 else 0.
|
noise = torch.randn_like(image_embed) if time_next > 0 else 0.
|
||||||
@@ -2893,16 +2906,25 @@ class Decoder(nn.Module):
|
|||||||
|
|
||||||
pred, _ = self.parse_unet_output(learned_variance, unet_output)
|
pred, _ = self.parse_unet_output(learned_variance, unet_output)
|
||||||
|
|
||||||
|
# predict x0
|
||||||
|
|
||||||
if predict_x_start:
|
if predict_x_start:
|
||||||
x_start = pred
|
x_start = pred
|
||||||
pred_noise = noise_scheduler.predict_noise_from_start(img, t = time_cond, x0 = pred)
|
|
||||||
else:
|
else:
|
||||||
x_start = noise_scheduler.predict_start_from_noise(img, t = time_cond, noise = pred)
|
x_start = noise_scheduler.predict_start_from_noise(img, t = time_cond, noise = pred)
|
||||||
pred_noise = pred
|
|
||||||
|
# maybe clip x0
|
||||||
|
|
||||||
if clip_denoised:
|
if clip_denoised:
|
||||||
x_start = self.dynamic_threshold(x_start)
|
x_start = self.dynamic_threshold(x_start)
|
||||||
|
|
||||||
|
# predict noise
|
||||||
|
|
||||||
|
if predict_x_start:
|
||||||
|
pred_noise = noise_scheduler.predict_noise_from_start(img, t = time_cond, x0 = pred)
|
||||||
|
else:
|
||||||
|
pred_noise = pred
|
||||||
|
|
||||||
c1 = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt()
|
c1 = eta * ((1 - alpha / alpha_next) * (1 - alpha_next) / (1 - alpha)).sqrt()
|
||||||
c2 = ((1 - alpha_next) - torch.square(c1)).sqrt()
|
c2 = ((1 - alpha_next) - torch.square(c1)).sqrt()
|
||||||
noise = torch.randn_like(img) if not is_last_timestep else 0.
|
noise = torch.randn_like(img) if not is_last_timestep else 0.
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
__version__ = '1.10.2'
|
__version__ = '1.10.5'
|
||||||
|
|||||||
Reference in New Issue
Block a user