conv3d_demo.py
import svetoviz_webgpu as sv
# 1. Prepare 3D volumetric data (Streaming from HF)
ds = load_dataset("g4m3r/T1w_MRI_Brain_Slices", split="train", streaming=True)
# 2. Skip first 2 noisy slices, take 30 consecutive coronal layers
slices = [np.array(ex['image'].convert("L")) for ex in ds.skip(2).take(30)]
input_volume = torch.from_numpy(np.stack(slices)).unsqueeze(0).unsqueeze(0)
# 3. Define the 3D Convolutional module
conv3d = nn.Conv3d(in_channels=1, out_channels=16, kernel_size=3, padding=1)
def terminal_callback(buffer, message, images, files):
# 4. Process volume (1, 1, 30, H, W) through the module
output = conv3d(input_volume)
buffer.send_system_message(f"Voxel Grid Ready. Shape: {list(output.shape)}")
# 5. Start the interactive session
sv.pytorch_web(module=conv3d, terminal_callback=terminal_callback)