zeropad2d_demo.py
import svetoviz_webgpu as sv
# 1. Prepare 2D image data (C, H, W)
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 ZeroPad2d
# padding=(left, right, top, bottom) -> Adds 10px black border
zeropad = nn.ZeroPad2d(padding=10)
def terminal_callback(buffer, message, images, files):
output = zeropad(input_tensor)
buffer.send_system_message(f"Original Resolution: {input_tensor.shape[2:]}")
buffer.send_system_message(f"Padded Resolution: {output.shape[2:]}")
buffer.send_system_message("Boundary expanded with zero-valued pixels (Black).")
# 3. Start the interactive session
sv.pytorch_web(module=zeropad, terminal_callback=terminal_callback)