torch.nn.functional.dropout3d
function dropout3d<S extends Shape, D extends DType = DType, Dev extends DeviceType = DeviceType>(input: Tensor<S, D, Dev>, options?: DropoutFunctionalOptions): Tensor<S, D, Dev>function dropout3d<S extends Shape, D extends DType = DType, Dev extends DeviceType = DeviceType>(input: Tensor<S, D, Dev>, p: number, training: boolean, inplace: boolean, options?: DropoutFunctionalOptions): Tensor<S, D, Dev>Randomly zeros out entire channels in 3D input (volumetric feature maps).
Applies channel-wise dropout for 3D volumetric data (medical imaging, video). Instead of dropping individual voxels, dropout3d drops entire feature maps consistently across all spatial dimensions (depth, height, width). This preserves 3D spatial structure and is the standard regularization for 3D CNNs and volumetric deep learning. Each channel is either completely dropped or completely kept, with the same mask applied to all D×H×W positions, maintaining the coherence of learned 3D features.
Common use cases:
- 3D medical imaging: CT/MRI volumetric analysis (brain tumors, lung nodules)
- 3D CNNs: Volumetric convolution networks for shape analysis
- Video analysis: Temporal convolutional networks treating video as 3D volumes
- Volumetric object detection: 3D bounding box prediction in point clouds or volumes
- Microscopy image analysis: 3D confocal microscopy stacks
- Geospatial volumetric data: 3D seismic or weather data analysis
- Skeleton/pose estimation: 3D human pose from volumetric representations
Key differences from 2D dropout:
- Operates on 3D volumes (D, H, W) instead of 2D images (H, W)
- Applies same mask across depth dimension (temporal or spatial)
- Preserves 3D volumetric coherence of learned features
- Essential for 3D CNN regularization
Dimensionality handling:
- 1D input (L,): Element-wise dropout applied
- 2D input (H, W): Channel dropout treating first dim as channels
- 3D input (D, H, W): Channel dropout treating first dim as channels
- 4D input (C, D, H, W): Channel dropout per channel
- 5D input (N, C, D, H, W): Batch-wise channel dropout (different mask per batch)
- Higher dims: Falls back to element-wise dropout
- Volumetric consistency: The same channel is either dropped or kept across all D×H×W spatial positions. All voxels of a feature map share the same fate
- 3D structure preservation: Unlike element-wise dropout, maintains the integrity of 3D learned features critical for volumetric analysis tasks
- Scaling factor: Kept channels are automatically scaled by 1/(1-p) to maintain expected value. This is inverted dropout - no rescaling needed at inference
- Independent per batch: With 5D input (N, C, D, H, W), each volume gets an independent random channel mask, improving regularization
- Standard for 3D CNNs: dropout3d is the de facto standard for volumetric CNNs. Use this over element-wise dropout for 3D spatial data
- Memory considerations: 3D volumes are memory-intensive. Consider smaller batch sizes or patch-based processing if memory is limited
- Deterministic eval: Always set training=false during inference for reproducible results
- Don't mix with batch_norm carelessly: Using both together can cause training instability. Modern practice often uses either batch_norm or dropout, not both heavily
- Scaling is automatic: The 1/(1-p) scaling is applied automatically during training. Don't manually rescale - that would cause incorrect statistics
- High dropout rates: Rates above 0.5 are uncommon and usually indicate too weak of a model. Consider regularizing through model size or L2 regularization instead
- Channel dimension position: This function assumes channels are at dimension 1. If your data has channels elsewhere, use permute/transpose first
- 3D computation cost: 3D convolutions and dropout are expensive. Use smaller spatial dimensions, patch-based processing, or pruning to manage computation
- 2D data needs dropout2d: This is for 3D volumetric data. Use dropout2d for 2D images or dropout1d for 1D sequences
Parameters
inputTensor<S, D, Dev>- Input tensor. Typical shapes: - (N, C, D, H, W): Batch of 3D volumes [batch, channels, depth, height, width] - (C, D, H, W): Unbatched 3D volume [channels, depth, height, width] - (D, H, W): Single 3D volume [depth, height, width] Where: N=batch size, C=channels, D=depth, H=height, W=width
optionsDropoutFunctionalOptionsoptional
Returns
Tensor<S, D, Dev>– Tensor with same shape as input, with channels dropped and scaledExamples
// Basic 3D channel dropout for volumetric data
const volumes = torch.randn(8, 32, 64, 64, 64); // 8 medical scans, 32 channels, 64³ voxels
const output = torch.nn.functional.dropout3d(volumes, 0.2, true);
// ~20% of the 32 channels are dropped entirely across all voxels// 3D CNN for medical image segmentation
const input = torch.randn(4, 1, 128, 128, 128); // 4 CT scans, 1 channel, 128³
const conv_out = new torch.nn.Conv3d(1, 32, 3, 1, 1).forward(input);
const regularized = torch.nn.functional.dropout3d(conv_out, 0.3, model.training);
const pooled = torch.nn.functional.max_pool3d(regularized, [2, 2, 2]);
// Channel dropout applied consistently across all spatial positions// Video classification with 3D CNN (treating as temporal volume)
const video = torch.randn(16, 3, 8, 112, 112); // 16 clips, RGB, 8 frames, 112×112
const conv1_out = new torch.nn.Conv3d(3, 64, (3, 3, 3), 1, 1).forward(video);
const relu1 = torch.nn.functional.relu(conv1_out);
const drop1 = torch.nn.functional.dropout3d(relu1, 0.2, true);
const pool1 = torch.nn.functional.max_pool3d(drop1, [1, 2, 2]);
// 3D dropout preserves temporal coherence in video// MRI brain scan processing
const brain_scans = torch.randn(6, 1, 256, 256, 256); // 6 brain MRIs
const encoder_out = torch.randn(6, 128, 32, 32, 32); // Encoder features
const dropped = torch.nn.functional.dropout3d(encoder_out, 0.25, true);
// Maintains 3D structure for accurate localization// Unbatched 3D volume (4D input)
const volume = torch.randn(64, 128, 128, 128); // 64 channels, 128³
const output = torch.nn.functional.dropout3d(volume, 0.1, true);
// output shape: [64, 128, 128, 128] with ~10% of channels masked// Training vs evaluation behavior
const batch = torch.randn(2, 16, 64, 64, 64);
const train_output = torch.nn.functional.dropout3d(batch, 0.2, true);
// During training: 20% channels dropped, all spatial positions affected
const eval_output = torch.nn.functional.dropout3d(batch, 0.2, false);
// During evaluation: No dropout, returns input unchanged// Progressive dropout in 3D ResNet
const input = torch.randn(4, 3, 128, 128, 128);
let x = input;
const drop_rates = [0.1, 0.1, 0.2, 0.2, 0.3];
for (let i = 0; i < drop_rates.length; i++) {
x = torch.nn.functional.dropout3d(x, drop_rates[i], model.training);
// Gradually increase dropout rate in deeper layers
}
// Common pattern: stronger regularization in deeper layers// 3D object detection in volumetric point clouds
const cloud_volume = torch.randn(16, 64, 32, 32, 32); // Voxelized point cloud
const features = torch.randn(16, 128, 16, 16, 16); // Feature extraction
const regularized = torch.nn.functional.dropout3d(features, 0.2, true);
const proposals = new torch.nn.Linear(128, 7).forward(regularized);
// 3D dropout helps with generalization in 3D detectionSee Also
- PyTorch torch.nn.functional.dropout3d
- dropout1d - Channel dropout for 1D sequences
- dropout2d - Channel dropout for 2D spatial data (images)
- dropout - Element-wise dropout (not channel-wise)
- feature_alpha_dropout - SELU-compatible channel dropout
- batch_norm - Alternative regularization using normalization
- layer_norm - Per-channel normalization
- max_pool3d - 3D spatial pooling
- Conv3d - 3D convolution layer