torch.nn.ZeroPad2d
new ZeroPad2d(padding: Padding2D)
- readonly
padding([number, number, number, number])
2D zero padding: pads images with black borders.
Standard image padding: fills with zeros creating black borders. Most common choice for CNNs and image processing despite boundary artifacts.
When to use ZeroPad2d:
- Standard CNN image processing
- Default padding for image networks
- When boundary artifacts acceptable
- Performance critical (simplest padding)
- Black borders: Creates visible black border on images
- Most common: Default choice in most image networks
- Artifacts: Boundary artifacts visible in some tasks
Examples
// Standard image padding
const pad = new torch.nn.ZeroPad2d(1);
const img = torch.randn([32, 3, 224, 224]);
const padded = pad.forward(img); // [32, 3, 226, 226] with black border