__init__.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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":
  17. from .det_mobilenet_v3 import MobileNetV3
  18. from .rec_hgnet import PPHGNet_small
  19. from .rec_lcnetv3 import PPLCNetV3
  20. from .rec_pphgnetv2 import PPHGNetV2_B4
  21. support_dict = [
  22. "MobileNetV3",
  23. "ResNet",
  24. "ResNet_vd",
  25. "ResNet_SAST",
  26. "PPLCNetV3",
  27. "PPHGNet_small",
  28. 'PPHGNetV2_B4',
  29. ]
  30. elif model_type == "rec" or model_type == "cls":
  31. from .rec_hgnet import PPHGNet_small
  32. from .rec_lcnetv3 import PPLCNetV3
  33. from .rec_mobilenet_v3 import MobileNetV3
  34. from .rec_svtrnet import SVTRNet
  35. from .rec_mv1_enhance import MobileNetV1Enhance
  36. from .rec_pphgnetv2 import PPHGNetV2_B4, PPHGNetV2_B6_Formula
  37. support_dict = [
  38. "MobileNetV1Enhance",
  39. "MobileNetV3",
  40. "ResNet",
  41. "ResNetFPN",
  42. "MTB",
  43. "ResNet31",
  44. "SVTRNet",
  45. "ViTSTR",
  46. "DenseNet",
  47. "PPLCNetV3",
  48. "PPHGNet_small",
  49. "PPHGNetV2_B4",
  50. "PPHGNetV2_B6_Formula"
  51. ]
  52. else:
  53. raise NotImplementedError
  54. module_name = config.pop("name")
  55. assert module_name in support_dict, Exception(
  56. "when model typs is {}, backbone only support {}".format(
  57. model_type, support_dict
  58. )
  59. )
  60. module_class = eval(module_name)(**config)
  61. return module_class