__init__.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (c) 2021 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. from .operators import *
  15. from .batch_operators import BatchRandomResize, BatchRandomResizeByShort, _BatchPadding
  16. from paddlex.cv import transforms as T
  17. def arrange_transforms(model_type, transforms, mode='train'):
  18. # 给transforms添加arrange操作
  19. if model_type == 'segmenter':
  20. if mode == 'eval':
  21. transforms.apply_im_only = True
  22. else:
  23. transforms.apply_im_only = False
  24. arrange_transform = ArrangeSegmenter(mode)
  25. elif model_type == 'classifier':
  26. arrange_transform = ArrangeClassifier(mode)
  27. elif model_type == 'detector':
  28. arrange_transform = ArrangeDetector(mode)
  29. else:
  30. raise Exception("Unrecognized model type: {}".format(model_type))
  31. transforms.arrange_outputs = arrange_transform
  32. def build_transforms(transforms_info):
  33. transforms = list()
  34. for op_info in transforms_info:
  35. op_name = list(op_info.keys())[0]
  36. op_attr = op_info[op_name]
  37. if not hasattr(T, op_name):
  38. raise Exception("There's no transform named '{}'".format(op_name))
  39. transforms.append(getattr(T, op_name)(**op_attr))
  40. eval_transforms = T.Compose(transforms)
  41. return eval_transforms