predictor_ml.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # copyright (c) 2024 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. import os
  15. import numpy as np
  16. from pathlib import Path
  17. from ...base import BasePredictor
  18. from ...base.predictor.transforms import image_common
  19. from .keys import ClsKeys as K
  20. from .utils import InnerConfig
  21. from ....utils import logging
  22. from . import transforms as T
  23. from .predictor import ClsPredictor
  24. from ..model_list import ML_MODELS
  25. class MLClsPredictor(ClsPredictor, BasePredictor):
  26. """ MLClssification Predictor """
  27. entities = ML_MODELS
  28. def _get_post_transforms_from_config(self):
  29. """ get postprocess transforms """
  30. post_transforms = self.other_src.post_transforms
  31. post_transforms.extend([
  32. T.PrintResult(), T.SaveMLClsResults(self.output,
  33. self.other_src.labels)
  34. ])
  35. return post_transforms