MaxUnpool3d

https://pytorch.org/docs/stable/generated/torch.nn.MaxUnpool3d.html

maxunpool3d_demo.py
import svetoviz_webgpu as sv

# 1. Prepare 3D MRI volume
ds = load_dataset("g4m3r/T1w_MRI_Brain_Slices", split="train", streaming=True)
slices = [np.array(ex['image'].resize((128, 128)).convert("L")).astype(np.float32) / 255.0 for ex in ds.skip(2).take(32)]
input_volume = torch.from_numpy(np.stack(slices)).unsqueeze(0).unsqueeze(0)

# 2. Define 3D Pooling and Unpooling
pool3d = nn.MaxPool3d(kernel_size=6, stride=2, return_indices=True)
unpool3d = nn.MaxUnpool3d(kernel_size=6, stride=2)
container = nn.ModuleList([pool3d, unpool3d])

def terminal_callback(buffer, message, images, files):
    # Forward pass to get indices
    pooled, indices = pool3d(input_volume)
    output = unpool3d(pooled, indices)

    buffer.send_system_message("Voxel-wise MaxUnpool3d completed.")
    buffer.send_system_message(f"Output Shape: {list(output.shape)}")

# 4. Start the interactive session
sv.pytorch_web(module=container, terminal_callback=terminal_callback)
Volumetric Voxel Restoration
MaxUnpool3d activations
This operation restores the 3D grid resolution by re-inserting compressed voxel data into its previous spatial coordinates.