mirror of
https://github.com/kohya-ss/sd-scripts.git
synced 2026-04-08 22:35:09 +00:00
Perlin noise
This commit is contained in:
@@ -410,9 +410,9 @@ def rand_perlin_2d_octaves(device, shape, res, octaves=1, persistence=0.5):
|
||||
amplitude *= persistence
|
||||
return noise
|
||||
|
||||
def perlin_noise(noise, device):
|
||||
def perlin_noise(noise, device,octaves):
|
||||
b, c, w, h = noise.shape()
|
||||
perlin = lambda : rand_perlin_2d_octaves(device,(w,h),(4,4),1)
|
||||
perlin = lambda : rand_perlin_2d_octaves(device,(w,h),(4,4),octaves)
|
||||
noise_perlin_r = torch.rand(noise.shape, device=device) + perlin()
|
||||
noise_perlin_g = torch.rand(noise.shape, device=device) + perlin()
|
||||
noise_perlin_b = torch.rand(noise.shape, device=device) + perlin()
|
||||
@@ -420,7 +420,7 @@ def perlin_noise(noise, device):
|
||||
(noise_perlin_r,
|
||||
noise_perlin_g,
|
||||
noise_perlin_b),
|
||||
2)
|
||||
1)
|
||||
return noise_perlin
|
||||
|
||||
|
||||
|
||||
@@ -2127,6 +2127,12 @@ def add_training_arguments(parser: argparse.ArgumentParser, support_dreambooth:
|
||||
default=None,
|
||||
help="enable multires noise with this number of iterations (if enabled, around 6-10 is recommended) / Multires noiseを有効にしてこのイテレーション数を設定する(有効にする場合は6-10程度を推奨)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--perlin_noise",
|
||||
type=int,
|
||||
default=None,
|
||||
help="enable perlin noise and set the octaves",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--multires_noise_discount",
|
||||
type=float,
|
||||
|
||||
@@ -23,7 +23,7 @@ from library.config_util import (
|
||||
BlueprintGenerator,
|
||||
)
|
||||
import library.custom_train_functions as custom_train_functions
|
||||
from library.custom_train_functions import apply_snr_weight, get_weighted_text_embeddings, pyramid_noise_like, apply_noise_offset
|
||||
from library.custom_train_functions import apply_snr_weight, get_weighted_text_embeddings, pyramid_noise_like, apply_noise_offset,perlin_noise
|
||||
|
||||
|
||||
def train(args):
|
||||
@@ -274,6 +274,8 @@ def train(args):
|
||||
noise = apply_noise_offset(latents, noise, args.noise_offset, args.adaptive_noise_scale)
|
||||
elif args.multires_noise_iterations:
|
||||
noise = pyramid_noise_like(noise, latents.device, args.multires_noise_iterations, args.multires_noise_discount)
|
||||
elif args.perlin_noise:
|
||||
noise = perlin_noise(noise,latents.device,args.perlin_noise)
|
||||
|
||||
# Get the text embedding for conditioning
|
||||
with torch.set_grad_enabled(global_step < args.stop_text_encoder_training):
|
||||
|
||||
Reference in New Issue
Block a user