tahamajs/DGM / PaperSLecturs /Generative_Codes /generative-models /sgm /modules /diffusionmodules /sigma_sampling.py
tahamajs/DGM / PaperSLecturs /Generative_Codes /generative-models /sgm /modules /diffusionmodules /sigma_sampling.py
| import torch | |
| from typing import Optional, Union | |
| from ...util import default, instantiate_from_config | |
| class EDMSampling: | |
| def __init__(self, p_mean=-1.2, p_std=1.2): | |
| self.p_mean = p_mean | |
| self.p_std = p_std | |
| def __call__(self, n_samples, rand=None): | |
| log_sigma = self.p_mean + self.p_std * default(rand, torch.randn((n_samples,))) | |
| return log_sigma.exp() | |
| class DiscreteSampling: | |
| def __init__(self, discretization_config, num_idx, do_append_zero=False, flip=True): | |
| self.num_idx = num_idx | |
| self.sigmas = instantiate_from_config(discretization_config)( | |
| num_idx, do_append_zero=do_append_zero, flip=flip | |
| ) | |
| def idx_to_sigma(self, idx): | |
| return self.sigmas[idx] | |
| def __call__(self, n_samples, rand=None): | |
| idx = default( | |
| rand, | |
| torch.randint(0, self.num_idx, (n_samples,)), | |
| ) | |
| return self.idx_to_sigma(idx) | |
| class ZeroSampler: | |
| def __call__( | |
| self, n_samples: int, rand: Optional[torch.Tensor] = None | |
| ) -> torch.Tensor: | |
| return torch.zeros_like(default(rand, torch.randn((n_samples,)))) + 1.0e-5 | |
Xet Storage Details
- Size:
- 1.15 kB
- Xet hash:
- 3d22a5b2f667de4f23d52bbd452afd94998288c8784e2f071a109e02efca6458
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.