__init__.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # copyright (c) 2020 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. from __future__ import absolute_import
  15. from __future__ import division
  16. from __future__ import print_function
  17. from __future__ import unicode_literals
  18. from .iaa_augment import IaaAugment
  19. from .make_border_map import MakeBorderMap
  20. from .make_shrink_map import MakeShrinkMap
  21. from .random_crop_data import EastRandomCropData, PSERandomCrop
  22. from .rec_img_aug import RecAug, RecResizeImg, ClsResizeImg, SRNRecResizeImg
  23. from .randaugment import RandAugment
  24. from .operators import *
  25. from .label_ops import *
  26. from .east_process import *
  27. from .sast_process import *
  28. def transform(data, ops=None):
  29. """ transform """
  30. if ops is None:
  31. ops = []
  32. for op in ops:
  33. data = op(data)
  34. if data is None:
  35. return None
  36. return data
  37. def create_operators(op_param_list, global_config=None):
  38. """
  39. create operators based on the config
  40. Args:
  41. params(list): a dict list, used to create some operators
  42. """
  43. assert isinstance(op_param_list, list), ('operator config should be a list')
  44. ops = []
  45. for operator in op_param_list:
  46. assert isinstance(operator,
  47. dict) and len(operator) == 1, "yaml format error"
  48. op_name = list(operator)[0]
  49. param = {} if operator[op_name] is None else operator[op_name]
  50. if global_config is not None:
  51. param.update(global_config)
  52. op = eval(op_name)(**param)
  53. ops.append(op)
  54. return ops