torch.nn.ConstantPad2d
class ConstantPad2d extends Modulenew ConstantPad2d(padding: Padding2D, value: number)
- readonly
padding([number, number, number, number]) - readonly
value(number)
2D constant padding: pads images with custom value.
Useful for image padding with custom values (e.g., dataset mean, special background).
When to use ConstantPad2d:
- Image padding with non-zero value (e.g., ImageNet mean)
- Special background color important
- Preprocessing pipeline with custom value
Examples
// Pad with ImageNet mean
const imagenet_mean = 0.485; // Typical value
const pad = new torch.nn.ConstantPad2d(7, imagenet_mean);
const img = torch.randn([32, 3, 224, 224]);
const padded = pad.forward(img);