pipeline.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. from typing import Any, Dict, Optional, Union, List
  15. import numpy as np
  16. from importlib import import_module
  17. from ...utils.pp_option import PaddlePredictorOption
  18. from ..base import BasePipeline
  19. module_3d_bev_detection_result = import_module(
  20. ".result", "paddlex.inference.models.3d_bev_detection"
  21. )
  22. BEV3DDetResult = getattr(module_3d_bev_detection_result, "BEV3DDetResult")
  23. class BEVDet3DPipeline(BasePipeline):
  24. """3D Detection Pipeline"""
  25. entities = "3d_bev_detection"
  26. def __init__(
  27. self,
  28. config: Dict,
  29. device: str = None,
  30. pp_option: PaddlePredictorOption = None,
  31. use_hpip: bool = False,
  32. ) -> None:
  33. """
  34. Initializes the class with given configurations and options.
  35. Args:
  36. config (Dict): Configuration dictionary containing model and other parameters.
  37. device (str): The device to run the prediction on. Default is None.
  38. pp_option (PaddlePredictorOption): Options for PaddlePaddle predictor. Default is None.
  39. use_hpip (bool): Whether to use high-performance inference (hpip) for prediction. Defaults to False.
  40. """
  41. super().__init__(device=device, pp_option=pp_option, use_hpip=use_hpip)
  42. bev_detection_3d_model_config = config["SubModules"]["3DBEVDetection"]
  43. self.bev_detection_3d_model = self.create_model(bev_detection_3d_model_config)
  44. def predict(
  45. self,
  46. input: Union[str, List[str], np.ndarray, List[np.ndarray]],
  47. **kwargs,
  48. ) -> BEV3DDetResult:
  49. """Predicts 3D detection results for the given input.
  50. Args:
  51. input (str | list[str] | np.ndarray | list[np.ndarray]): The input path(s) to the 3d annotation pickle file.
  52. **kwargs: Additional keyword arguments that can be passed to the function.
  53. Returns:
  54. BEV3DDetResult: The predicted 3d detection results.
  55. """
  56. yield from self.bev_detection_3d_model(input)