InstanceNorm2d

https://pytorch.org/docs/stable/generated/torch.nn.InstanceNorm2d.html

instancenorm2d_demo.py
import svetoviz_webgpu as sv

# 1. Prepare 2D image data
input_tensor = torch.from_numpy(img_np).permute(2, 0, 1).unsqueeze(0)

# 2. Define InstanceNorm2d
in2d = nn.InstanceNorm2d(num_features=3)

def terminal_callback(buffer, message, images, files):
    output = in2d(input_tensor)

    buffer.send_system_message(f"Resolution: {input_tensor.shape[2:]}")
    buffer.send_system_message("Status: Contrast normalized per image channel.")
    buffer.send_system_message("Application: Common in real-time artistic style transfer.")

# 3. Start the interactive session
sv.pytorch_web(module=in2d, terminal_callback=terminal_callback)
Style and Contrast Invariance
InstanceNorm2d activations
In vision tasks, InstanceNorm2d treats each image as a separate entity. By normalizing the mean and variance of each channel, it effectively "wastes" the style/contrast information of the specific image, forcing the network to focus on content—a technique pioneered for Style Transfer and GANs.