__init__.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
  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. __all__ = ["build_backbone"]
  15. def build_backbone(config, model_type):
  16. if model_type == "det" or model_type == "table":
  17. from .det_mobilenet_v3 import MobileNetV3
  18. from .det_resnet import ResNet
  19. from .det_resnet_vd import ResNet_vd
  20. from .det_resnet_vd_sast import ResNet_SAST
  21. from .det_pp_lcnet import PPLCNet
  22. support_dict = [
  23. "MobileNetV3", "ResNet", "ResNet_vd", "ResNet_SAST", "PPLCNet"
  24. ]
  25. if model_type == "table":
  26. from .table_master_resnet import TableResNetExtra
  27. support_dict.append('TableResNetExtra')
  28. elif model_type == "rec" or model_type == "cls":
  29. from .rec_mobilenet_v3 import MobileNetV3
  30. from .rec_resnet_vd import ResNet
  31. from .rec_resnet_fpn import ResNetFPN
  32. from .rec_mv1_enhance import MobileNetV1Enhance
  33. from .rec_nrtr_mtb import MTB
  34. from .rec_resnet_31 import ResNet31
  35. from .rec_resnet_32 import ResNet32
  36. from .rec_resnet_45 import ResNet45
  37. from .rec_resnet_aster import ResNet_ASTER
  38. from .rec_micronet import MicroNet
  39. from .rec_efficientb3_pren import EfficientNetb3_PREN
  40. from .rec_svtrnet import SVTRNet
  41. from .rec_vitstr import ViTSTR
  42. from .rec_resnet_rfl import ResNetRFL
  43. from .rec_densenet import DenseNet
  44. support_dict = [
  45. 'MobileNetV1Enhance', 'MobileNetV3', 'ResNet', 'ResNetFPN', 'MTB',
  46. 'ResNet31', 'ResNet45', 'ResNet_ASTER', 'MicroNet',
  47. 'EfficientNetb3_PREN', 'SVTRNet', 'ViTSTR', 'ResNet32', 'ResNetRFL',
  48. 'DenseNet'
  49. ]
  50. elif model_type == 'e2e':
  51. from .e2e_resnet_vd_pg import ResNet
  52. support_dict = ['ResNet']
  53. elif model_type == 'kie':
  54. from .kie_unet_sdmgr import Kie_backbone
  55. from .vqa_layoutlm import LayoutLMForSer, LayoutLMv2ForSer, LayoutLMv2ForRe, LayoutXLMForSer, LayoutXLMForRe
  56. support_dict = [
  57. 'Kie_backbone', 'LayoutLMForSer', 'LayoutLMv2ForSer',
  58. 'LayoutLMv2ForRe', 'LayoutXLMForSer', 'LayoutXLMForRe'
  59. ]
  60. elif model_type == 'table':
  61. from .table_resnet_vd import ResNet
  62. from .table_mobilenet_v3 import MobileNetV3
  63. support_dict = ['ResNet', 'MobileNetV3']
  64. else:
  65. raise NotImplementedError
  66. module_name = config.pop('name')
  67. assert module_name in support_dict, Exception(
  68. "when model typs is {}, backbone only support {}".format(model_type,
  69. support_dict))
  70. module_class = eval(module_name)(**config)
  71. return module_class