replication_pad3d_demo.py
import svetoviz_webgpu as sv
# 1. Prepare 3D volume (e.g., 32 slices)
input_volume = torch.from_numpy(np.stack(slices)).unsqueeze(0).unsqueeze(0)
# 2. Define ReplicationPad3d (Pads 2 voxels across all dimensions)
pad3d = nn.ReplicationPad3d(padding=2)
def terminal_callback(buffer, message, images, files):
output = pad3d(input_volume)
buffer.send_system_message(f"Input Voxel Grid: {input_volume.shape[2:]}")
buffer.send_system_message(f"Padded Voxel Grid: {output.shape[2:]}")
buffer.send_system_message("Volumetric edge-clamping applied to all dimensions.")
# 3. Start the interactive session
sv.pytorch_web(module=pad3d, terminal_callback=terminal_callback)