det_pse_head.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """
  15. This code is refer from:
  16. https://github.com/whai362/PSENet/blob/python3/models/head/psenet_head.py
  17. """
  18. from paddle import nn
  19. class PSEHead(nn.Layer):
  20. def __init__(self, in_channels, hidden_dim=256, out_channels=7, **kwargs):
  21. super(PSEHead, self).__init__()
  22. self.conv1 = nn.Conv2D(
  23. in_channels, hidden_dim, kernel_size=3, stride=1, padding=1
  24. )
  25. self.bn1 = nn.BatchNorm2D(hidden_dim)
  26. self.relu1 = nn.ReLU()
  27. self.conv2 = nn.Conv2D(
  28. hidden_dim, out_channels, kernel_size=1, stride=1, padding=0
  29. )
  30. def forward(self, x, **kwargs):
  31. out = self.conv1(x)
  32. out = self.relu1(self.bn1(out))
  33. out = self.conv2(out)
  34. return {"maps": out}