transform.py 850 B

1234567891011121314151617181920212223242526272829303132333435
  1. # !/usr/bin/env python3
  2. # -*- coding: UTF-8 -*-
  3. ################################################################################
  4. #
  5. # Copyright (c) 2024 Baidu.com, Inc. All Rights Reserved
  6. #
  7. ################################################################################
  8. """
  9. Author: PaddlePaddle Authors
  10. """
  11. import abc
  12. from .utils.mixin import FromDictMixin
  13. from .utils.batch import batchable_method
  14. from .utils.node import Node
  15. class BaseTransform(FromDictMixin, Node):
  16. """ BaseTransform """
  17. @batchable_method
  18. def __call__(self, data):
  19. self.check_input_keys(data)
  20. data = self.apply(data)
  21. self.check_output_keys(data)
  22. return data
  23. @abc.abstractmethod
  24. def apply(self, data):
  25. """ apply """
  26. raise NotImplementedError
  27. def __str__(self):
  28. return self.__class__.__name__