Add spatial smoothing to remove latent grid artifacts
The per-element correction creates a visible mesh pattern at the VAE's 8x8 patch boundaries. A 3x3 box blur in latent space (24x24 pixels) smooths adjacent corrections while preserving the large-scale correction structure. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
8
nodes.py
8
nodes.py
@@ -1,4 +1,5 @@
|
|||||||
import torch
|
import torch
|
||||||
|
import torch.nn.functional as F
|
||||||
|
|
||||||
|
|
||||||
class SMCCFGCtrl:
|
class SMCCFGCtrl:
|
||||||
@@ -101,6 +102,13 @@ class SMCCFGCtrl:
|
|||||||
phi = s.std().clamp(min=1e-6)
|
phi = s.std().clamp(min=1e-6)
|
||||||
u_sw = -K_eff * torch.tanh(s / phi)
|
u_sw = -K_eff * torch.tanh(s / phi)
|
||||||
|
|
||||||
|
# Spatial smoothing: the per-element correction creates a grid
|
||||||
|
# pattern at latent boundaries (each latent = 8x8 pixels). A mild
|
||||||
|
# 3x3 box blur in latent space removes these artifacts while
|
||||||
|
# preserving the large-scale correction structure.
|
||||||
|
if u_sw.ndim == 4:
|
||||||
|
u_sw = F.avg_pool2d(u_sw, kernel_size=3, stride=1, padding=1)
|
||||||
|
|
||||||
# Corrected guidance error (in normalized noise space)
|
# Corrected guidance error (in normalized noise space)
|
||||||
guidance_eps = guidance_eps + u_sw
|
guidance_eps = guidance_eps + u_sw
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user