det_pse_head.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. self.bn1 = nn.BatchNorm2D(hidden_dim)
  25. self.relu1 = nn.ReLU()
  26. self.conv2 = nn.Conv2D(
  27. hidden_dim, out_channels, kernel_size=1, stride=1, padding=0)
  28. def forward(self, x, **kwargs):
  29. out = self.conv1(x)
  30. out = self.relu1(self.bn1(out))
  31. out = self.conv2(out)
  32. return {'maps': out}