You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

padding.py 743 B

123456789101112131415161718192021222324252627
  1. from typing import Tuple
  2. from ..functional import nn
  3. from .module import Module
  4. class Pad(Module):
  5. """
  6. Pad is python warpper for padding opr in megbrain, can padding in random one of the max 7 dimensions.
  7. Supported constant, edge(replicate) and reflect mode, constatnt is the default mode.
  8. """
  9. def __init__(
  10. self,
  11. pad_witdth: Tuple[Tuple[int, int], ...],
  12. mode: str = "constant",
  13. constant_val: float = 0.0,
  14. ):
  15. super().__init__()
  16. self.pad_width = pad_witdth
  17. self.mode = mode
  18. self.pad_val = constant_val
  19. def forward(self, src):
  20. return nn.pad(
  21. src, pad_witdth=self.pad_width, mode=self.mode, constant_value=self.pad_val
  22. )