From a6f4249464a77482f6a61ed195f8a30979a001c8 Mon Sep 17 00:00:00 2001 From: blepping Date: Sat, 17 Feb 2024 15:07:58 -0700 Subject: [PATCH] Fix perlin noise for Cascade, (hopefully) fix power noise for batch size > 1 --- py/noise.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/py/noise.py b/py/noise.py index daf6735..bcf52f1 100644 --- a/py/noise.py +++ b/py/noise.py @@ -261,7 +261,7 @@ def rand_perlin_like(x): noise += perlin_noise( (noise_height, noise_width), (noise_height, noise_width), - batch_size=4, + batch_size=x.shape[1], # This should be the number of channels. ).to(x.device) return noise / noise.std() @@ -370,6 +370,7 @@ def power_noise_like(tensor, alpha=2, k=1): # This doesn't work properly right tensor = torch.randn_like(tensor) fft = torch.fft.fft2(tensor) freq = torch.arange(1, len(fft) + 1, dtype=torch.float) + freq = freq.reshape(freq.shape + (1,) * (len(tensor.shape) - 1)) spectral_density = k / freq**alpha noise = torch.rand(tensor.shape) * spectral_density mean = torch.mean(noise, dim=(-2, -1), keepdim=True).to(tensor.device)