batchnorm3d_demo.py
import svetoviz_webgpu as sv
# 1. Prepare 3D volume (Batch=1, Channels=1, D, H, W)
input_volume = torch.from_numpy(np.stack(slices)).unsqueeze(0).unsqueeze(0)
# 2. Define BatchNorm3d
bn3d = nn.BatchNorm3d(num_features=1)
def terminal_callback(buffer, message, images, files):
bn3d.train()
output = bn3d(input_volume)
buffer.send_system_message(f"Voxel Grid: {list(input_volume.shape)}")
buffer.send_system_message("Status: Volumetric normalization applied per 3D feature map.")
# 3. Start the interactive session
sv.pytorch_web(module=bn3d, terminal_callback=terminal_callback)