LPPool2d

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

lppool2d_demo.py
import svetoviz_webgpu as sv

# 1. Prepare 2D image data
img = Image.open("sample_image.jpg").convert("RGB")
img_np = np.array(img).astype(np.float32) / 255.0
input_tensor = torch.from_numpy(img_np).permute(2, 0, 1).unsqueeze(0)

# 2. Define LPPool2d
# Using p=2 for Euclidean norm pooling across spatial windows
pool2d = nn.LPPool2d(norm_type=2, kernel_size=6, stride=4)

def terminal_callback(buffer, message, images, files):
    # 3. Process the image through the module
    output = pool2d(input_tensor)

    buffer.send_system_message(f"Input Image: {list(input_tensor.shape)}")
    buffer.send_system_message(f"LP Pooled Output (p=2): {list(output.shape)}")

# 4. Start the interactive session
sv.pytorch_web(module=pool2d, terminal_callback=terminal_callback)
Spatial Energy Pooling
LPPool2d activations
Spatial p-norm pooling acts as a tunable feature extractor that can favor high-frequency signals more than standard averaging.