torch.nn.ReflectionPad3d
class ReflectionPad3d extends Modulenew ReflectionPad3d(padding: Padding3D)
- readonly
padding([number, number, number, number, number, number])
3D reflection padding: pads by reflecting volumes at boundaries.
Extends 3D spatial data (videos, medical volumes) by reflecting at all six faces. Mirrors depth, height, and width independently for smooth volumetric boundaries. Essential for:
- Video processing (temporal and spatial smooth padding)
- Medical imaging (CT/MRI volumes without artifacts)
- 3D object detection (smooth boundaries in 3D space)
- Volumetric CNNs (reduced edge artifacts)
- 3D style transfer and generation
3D reflection mirrors all three spatial dimensions: corners reflect along three axes, edges reflect along two axes, faces reflect across one axis.
When to use ReflectionPad3d:
- Video/temporal data (smooth motion at boundaries)
- Medical imaging (realistic boundary extension)
- 3D volumetric networks (smooth spatial padding)
- Dynamic 3D content (avoids temporal/spatial artifacts)
Trade-offs:
- vs ZeroPad3d: Reflection smoother; zero simpler but creates artifacts
- vs ReplicationPad3d: Reflection avoids face repetition
- Computation: More complex than zero padding
- 3D corners: All 8 corners reflect along three axes simultaneously
- Smooth 3D: Maintains 3D continuity in all directions
- Temporal/spatial: Works for both video temporal dimension and spatial dims
Examples
// Video padding
const pad = new torch.nn.ReflectionPad3d(1);
const video = torch.randn([8, 3, 30, 224, 224]); // [batch, channels, frames, height, width]
const padded = pad.forward(video); // [8, 3, 32, 226, 226]// Medical volume: asymmetric padding
const pad = new torch.nn.ReflectionPad3d([1, 1, 2, 2, 1, 1]);
const volume = torch.randn([1, 1, 128, 128, 128]); // [batch, channels, depth, H, W]
const padded = pad.forward(volume); // [1, 1, 130, 132, 130]