torch.nn.LazyInstanceNorm2d
class LazyInstanceNorm2d extends _LazyInstanceNormLazy Instance Normalization 2D: automatically infers channels for 2D instance normalization.
Extends InstanceNorm2d with lazy initialization. Normalizes each image's channels independently. Essential for style transfer (CycleGAN, MUNIT) and unpaired image-to-image translation.
- Style transfer: Standard in CycleGAN and style transfer networks
- Per-instance: Each sample normalized independently (no batch averaging)
- Content preservation: Removes style/contrast while keeping content structure
Examples
// Style transfer network
const lazy_in = new torch.nn.LazyInstanceNorm2d();
const x = torch.randn([4, 3, 256, 256]); // [batch, RGB, height, width]
const normalized = lazy_in.forward(x); // Initializes with 3 channels
// Each image's channels normalized independently