basic.py 931 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: utf-8 -*-
  2. # @Time : 2019/12/6 11:19
  3. # @Author : zhoujun
  4. from paddle import nn
  5. class ConvBnRelu(nn.Layer):
  6. def __init__(
  7. self,
  8. in_channels,
  9. out_channels,
  10. kernel_size,
  11. stride=1,
  12. padding=0,
  13. dilation=1,
  14. groups=1,
  15. bias=True,
  16. padding_mode="zeros",
  17. inplace=True,
  18. ):
  19. super().__init__()
  20. self.conv = nn.Conv2D(
  21. in_channels=in_channels,
  22. out_channels=out_channels,
  23. kernel_size=kernel_size,
  24. stride=stride,
  25. padding=padding,
  26. dilation=dilation,
  27. groups=groups,
  28. bias_attr=bias,
  29. padding_mode=padding_mode,
  30. )
  31. self.bn = nn.BatchNorm2D(out_channels)
  32. self.relu = nn.ReLU()
  33. def forward(self, x):
  34. x = self.conv(x)
  35. x = self.bn(x)
  36. x = self.relu(x)
  37. return x