Draws stratified samples from a uniform distribution.
(shape, group=0, groups=1, dtype=None, device=None)
| 171 | |
| 172 | # copy from https://github.com/crowsonkb/k-diffusion.git |
| 173 | def stratified_uniform(shape, group=0, groups=1, dtype=None, device=None): |
| 174 | """Draws stratified samples from a uniform distribution.""" |
| 175 | if groups <= 0: |
| 176 | raise ValueError(f"groups must be positive, got {groups}") |
| 177 | if group < 0 or group >= groups: |
| 178 | raise ValueError(f"group must be in [0, {groups})") |
| 179 | n = shape[-1] * groups |
| 180 | offsets = torch.arange(group, n, groups, dtype=dtype, device=device) |
| 181 | u = torch.rand(shape, dtype=dtype, device=device) |
| 182 | return (offsets + u) / n |
| 183 | |
| 184 | |
| 185 | def rand_cosine_interpolated(shape, image_d, noise_d_low, noise_d_high, sigma_data=1., min_value=1e-3, max_value=1e3, |
no outgoing calls
no test coverage detected