zeropad3d_demo.py
import svetoviz_webgpu as sv
# 1. Prepare 3D volumetric data (Batch, Channels, Depth, Height, Width)
# Simulating a small 16x16x16 voxel grid
input_tensor = torch.randn(1, 1, 16, 16, 16)
# 2. Define ZeroPad3d
# Adds 2 zeros to all 6 boundaries (left, right, top, bottom, front, back)
zeropad = nn.ZeroPad3d(padding=2)
def terminal_callback(buffer, message, images, files):
output = zeropad(input_tensor)
buffer.send_system_message(f"Input Volumetric Shape: {list(input_tensor.shape[2:])}")
buffer.send_system_message(f"Padded Volumetric Shape: {list(output.shape[2:])}")
buffer.send_system_message("Voxel grid expanded with zero-padding across 3 dimensions.")
# 3. Start the interactive session
sv.pytorch_web(module=zeropad, terminal_callback=terminal_callback)