__init__.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. import copy
  15. def build_loss(config):
  16. # det loss
  17. from .det_db_loss import DBLoss
  18. from .det_east_loss import EASTLoss
  19. from .det_sast_loss import SASTLoss
  20. # rec loss
  21. from .rec_ctc_loss import CTCLoss
  22. from .rec_att_loss import AttentionLoss
  23. from .rec_srn_loss import SRNLoss
  24. # cls loss
  25. from .cls_loss import ClsLoss
  26. support_dict = [
  27. 'DBLoss', 'EASTLoss', 'SASTLoss', 'CTCLoss', 'ClsLoss', 'AttentionLoss',
  28. 'SRNLoss'
  29. ]
  30. config = copy.deepcopy(config)
  31. module_name = config.pop('name')
  32. assert module_name in support_dict, Exception('loss only support {}'.format(
  33. support_dict))
  34. module_class = eval(module_name)(**config)
  35. return module_class