torch.nn.Dropout3d
new Dropout3d(options?: DropoutOptions)
- readonly
p(number)
Dropout3d: randomly zeros entire feature volumes for 3D spatial data (volumetric).
A specialized dropout for 3D volumetric data (medical imaging, volumetric CNNs, videos). Instead of dropping individual voxels, Dropout3d drops entire 3D feature volumes (all spatial locations D × H × W for a channel) together. This preserves volumetric coherence in 3D conv networks. Essential for:
- 3D convolutional networks (medical imaging, CT/MRI)
- Volumetric feature coherence preservation
- Video understanding with 3D convolutions
- Large-scale volumetric models
- Avoiding spatial fragmentation in 3D features
Dropout3d treats each feature volume as a unit: if a feature channel is dropped, ALL spatial voxels (all D × H × W locations) for that channel are zeroed. This is appropriate for 3D CNNs where learned 3D filters create meaningful volumetric patterns.
When to use Dropout3d:
- 3D convolutional layers (drop entire 3D feature maps)
- Medical imaging (CT, MRI, segmentation)
- Video understanding networks
- 3D object detection/classification
- Volumetric data processing
- When volumetric coherence within features is important
Why channel-wise dropout for volumes:
- Dropout: Drops each voxel x[d, h, w, c] independently
- Dropout3d: Drops x[:, :, :, c] together (entire 3D feature volume)
- Result: Preserves 3D spatial patterns while regularizing feature selection
- Rationale: 3D filters create coherent volumetric features; voxel-wise dropout breaks structure
Trade-offs:
- vs Dropout: Channel-wise preserves volumetric structure, essential for 3D data
- vs Dropout: Channel-wise much stronger regularization (entire 3D volumes dropped)
- Volumetric coherence: Assumes features have meaning across 3D regions
- Computational cost: Same as other dropout variants
Input shape expectations:
- 5D tensor: (batch, channels, depth, height, width) from Conv3d
- Standard format for 3D convolutional networks
Dropout3d mechanics: For input shape (N, C, D, H, W) where C is channels, D/H/W are spatial dimensions:
- Create channel mask M ~ Bernoulli(1-p) of shape (N, C, 1, 1, 1)
- Broadcast mask to (N, C, D, H, W): expand across all spatial dimensions
- Apply: y = M ⊙ x / (1-p) (entire 3D feature volumes zeroed or kept together)
- Channel-wise: Entire 3D feature volume (all D × H × W) dropped together
- Volumetric coherence: Preserves 3D patterns within feature volumes
- Conv3d designed: Works naturally with Conv3d output (B, C, D, H, W)
- Medical imaging: Standard in medical image analysis networks
- Feature selection: Acts as stochastic 3D feature selection
- Shape sensitive: Assumes input is (batch, channels, depth, height, width)
- Large spatial drops: Drops all D × H × W voxels in feature volumes
- Training/inference: Must call .train()/.eval() to control behavior
- Memory intensive: 3D data is large; consider lower dropout rates
Examples
// Dropout in 3D Conv network
const dropout = new torch.nn.Dropout3d(0.5);
const x = torch.randn([8, 64, 32, 64, 64]); // Batch=8, channels=64, D/H/W=32/64/64
// During training: ~50% of the 64 feature volumes are completely dropped
dropout.train();
const train_out = dropout.forward(x); // Shape [8, 64, 32, 64, 64], some volumes are zero
// During inference: no dropout
dropout.eval();
const test_out = dropout.forward(x); // No dropout, returns x// Medical imaging 3D CNN with dropout
class MedicalImageNet extends torch.nn.Module {
conv1: torch.nn.Conv3d;
dropout1: torch.nn.Dropout3d;
conv2: torch.nn.Conv3d;
dropout2: torch.nn.Dropout3d;
pool: torch.nn.MaxPool3d;
fc: torch.nn.Linear;
constructor() {
super();
this.conv1 = new torch.nn.Conv3d(1, 64, 3, { padding: 1 }); // CT/MRI input
this.dropout1 = new torch.nn.Dropout3d(0.3);
this.conv2 = new torch.nn.Conv3d(64, 128, 3, { padding: 1 });
this.dropout2 = new torch.nn.Dropout3d(0.3);
this.pool = new torch.nn.MaxPool3d(2);
this.fc = new torch.nn.Linear(128 * 16 * 16 * 16, 2); // Binary classification
}
forward(x: torch.Tensor): torch.Tensor {
x = torch.relu(this.conv1.forward(x));
x = this.dropout1.forward(x); // Drop 3D feature volumes
x = torch.relu(this.conv2.forward(x));
x = this.dropout2.forward(x);
x = this.pool.forward(x);
x = x.view([x.shape[0], -1]);
return this.fc.forward(x);
}
}// Video understanding with 3D convolutions
class VideoClassifier extends torch.nn.Module {
conv3d: torch.nn.Conv3d;
dropout: torch.nn.Dropout3d;
constructor() {
super();
// Input: (batch, channels, frames, height, width)
this.conv3d = new torch.nn.Conv3d(3, 64, [3, 3, 3], { padding: 1 });
this.dropout = new torch.nn.Dropout3d(0.4);
}
forward(x: torch.Tensor): torch.Tensor {
// x shape: [batch, 3, 16, 224, 224] (16 frames)
x = torch.relu(this.conv3d.forward(x));
x = this.dropout.forward(x); // Drop 3D feature volumes preserving temporal structure
return x;
}
}// 3D ResNet block with dropout
class ResidualBlock3D extends torch.nn.Module {
conv1: torch.nn.Conv3d;
dropout1: torch.nn.Dropout3d;
conv2: torch.nn.Conv3d;
dropout2: torch.nn.Dropout3d;
constructor(channels: number) {
super();
this.conv1 = new torch.nn.Conv3d(channels, channels, 3, { padding: 1 });
this.dropout1 = new torch.nn.Dropout3d(0.2);
this.conv2 = new torch.nn.Conv3d(channels, channels, 3, { padding: 1 });
this.dropout2 = new torch.nn.Dropout3d(0.2);
}
forward(x: torch.Tensor): torch.Tensor {
const residual = x;
let out = torch.relu(this.conv1.forward(x));
out = this.dropout1.forward(out);
out = this.conv2.forward(out);
out = this.dropout2.forward(out);
return torch.relu(out.add(residual)); // Residual connection
}
}