tweaks to latent corrections

This commit is contained in:
Vladimir Mandic
2024-02-02 18:24:44 -05:00
parent 5c9ca793e9
commit 94332fe2c6
13 changed files with 68 additions and 78 deletions
+18 -16
View File
@@ -14,7 +14,7 @@ debug('Trace: HDR')
def sharpen_tensor(tensor, ratio=0):
if ratio == 0:
print("early exit...")
debug("Sharpen: Early exit")
return tensor
kernel = torch.ones((3, 3), dtype=tensor.dtype, device=tensor.device)
kernel[1, 1] = 5.0
@@ -71,20 +71,22 @@ def correction(p, timestep, latent):
if timestep > 950 and p.hdr_clamp:
p.extra_generation_params["HDR clamp"] = f'{p.hdr_threshold}/{p.hdr_boundary}'
latent = soft_clamp_tensor(latent, threshold=p.hdr_threshold, boundary=p.hdr_boundary)
if 500 < timestep < 800 and (p.hdr_center or p.hdr_brightness):
p.extra_generation_params["HDR center"] = f'{p.hdr_color_correction}/{p.hdr_brightness}'
latent[0:1] = center_tensor(latent[0:1], full_shift=float(p.hdr_center), offset=p.hdr_brightness) # Brightness
p.hdr_center = 0
p.hdr_brightness = 0
if 500 < timestep < 800 and p.hdr_color_correction != 0:
latent[1:] = center_tensor(latent[1:], channel_shift=p.hdr_color_correction, full_shift=0.0) # Color
p.hdr_color_correction = 0
if timestep < p.hdr_sharpen_start and p.hdr_sharpen:
print(f"Sharpening... {p.hdr_sharpen_ratio}/{p.hdr_sharpen_start}")
p.extra_generation_params["HDR sharpen"] = f'{p.hdr_sharpen_ratio}/{p.hdr_sharpen_start}'
latent = sharpen_tensor(latent, ratio=p.hdr_sharpen_ratio)
# p.hdr_sharpen = False
p.hdr_sharpen_ratio *= 0.5 * 2**0.5
if 500 < timestep < 800 and (p.hdr_brightness != 0 or p.hdr_color != 0):
p.extra_generation_params["HDR center"] = f'{p.hdr_color}/{p.hdr_brightness}'
if p.hdr_brightness != 0:
latent[0:1] = center_tensor(latent[0:1], full_shift=float(p.hdr_mode), offset=2*p.hdr_brightness) # Brightness
p.extra_generation_params["HDR brightness"] = f'{p.hdr_brightness}'
p.hdr_brightness = 0
if p.hdr_color != 0:
latent[1:] = center_tensor(latent[1:], channel_shift=p.hdr_color, full_shift=float(p.hdr_mode)) # Color
p.extra_generation_params["HDR color"] = f'{p.hdr_color}'
p.hdr_color = 0
if timestep < 350 and p.hdr_sharpen != 0:
p.extra_generation_params["HDR sharpen"] = f'{p.hdr_sharpen}'
per_step_ratio = 2 ** (timestep / 250) * p.hdr_sharpen / 16
if abs(per_step_ratio) > 0.01:
debug(f"HDR Sharpen: timestep={timestep} ratio={p.hdr_sharpen} val={per_step_ratio}")
latent = sharpen_tensor(latent, ratio=per_step_ratio)
if 1 < timestep < 100 and p.hdr_maximize:
p.extra_generation_params["HDR max"] = f'{p.hdr_max_center}/{p.hdr_max_boundry}'
latent = center_tensor(latent, channel_shift=p.hdr_max_center, full_shift=1.0)
@@ -93,7 +95,7 @@ def correction(p, timestep, latent):
def correction_callback(p, timestep, kwargs):
if not any([p.hdr_clamp, p.hdr_center, p.hdr_maximize, p.hdr_sharpen, p.hdr_color_correction, p.hdr_brightness]):
if not any([p.hdr_clamp, p.hdr_mode, p.hdr_maximize, p.hdr_sharpen, p.hdr_color, p.hdr_brightness]):
return kwargs
latents = kwargs["latents"]
debug('')