(self, x_start, t, noise=None)
| 666 | return img |
| 667 | |
| 668 | def q_sample(self, x_start, t, noise=None): |
| 669 | noise = default(noise, lambda: torch.randn_like(x_start)) |
| 670 | |
| 671 | # fix gama |
| 672 | # \sqrt{\bar {\alpha_t}} \times x_0 + \sqrt{1 - \bar {\alpha_t}} * \epsilon |
| 673 | # also call VP schedule |
| 674 | |
| 675 | # SNR: self.sqrt_alphas_cumprod / self.sqrt_one_minus_alphas_cumprod |
| 676 | # SNR weighting: max(self.sqrt_alphas_cumprod **2 / self.sqrt_one_minus_alphas_cumprod**2, 1) |
| 677 | # or (1 + self.sqrt_alphas_cumprod **2 / self.sqrt_one_minus_alphas_cumprod**2) |
| 678 | return ( |
| 679 | extract(self.sqrt_alphas_cumprod, t, x_start.shape) * x_start |
| 680 | + extract(self.sqrt_one_minus_alphas_cumprod, t, x_start.shape) * noise |
| 681 | ) |
| 682 | # random gama |
| 683 | # x_shape = x_start.shape |
| 684 | # l = self.alphas_cumprod .gather(-1, t) |
| 685 | # r = self.alphas_cumprod .gather(-1, t+1) |
| 686 | # gama = (r - l) * torch.rand(0, 1) + l |
| 687 | # gama = gama.reshape(t.shape[0], *((1,) * (len(x_shape) - 1))) |
| 688 | # return ( |
| 689 | # nq.sqrt(gama) * x_start + nq.sqrt(1-gama)* noise |
| 690 | # ) |
| 691 | |
| 692 | def p_losses(self, x_start, noise=None, cond=None): |
| 693 | [b, c, h, w] = x_start.shape |
no test coverage detected