trainer.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 pathlib import Path
  15. from ..base import BaseTrainer
  16. from ...utils.config import AttrDict
  17. from ...utils import logging
  18. from .model_list import MODELS
  19. class BEVFusionTrainer(BaseTrainer):
  20. """3D BEV Detection Model Trainer"""
  21. entities = MODELS
  22. def _update_dataset(self):
  23. """update dataset settings"""
  24. self.pdx_config.update_dataset(
  25. self.global_config.dataset_dir,
  26. self.global_config.get("datart_prefix", True),
  27. "NuscenesMMDataset",
  28. version=self.global_config.get("version", "mini"),
  29. )
  30. def _update_pretrained_model(self):
  31. self.pdx_config.update_pretrained_model(
  32. self.global_config.load_cam_from, self.global_config.load_lidar_from
  33. )
  34. def update_config(self):
  35. """update training config"""
  36. self._update_dataset()
  37. self._update_pretrained_model()
  38. if self.train_config.batch_size is not None:
  39. self.pdx_config.update_batch_size(self.train_config.batch_size)
  40. if self.train_config.learning_rate is not None:
  41. self.pdx_config.update_learning_rate(self.train_config.learning_rate)
  42. if self.train_config.epochs_iters is not None:
  43. self.pdx_config.update_epochs(self.train_config.epochs_iters)
  44. epochs_iters = self.train_config.epochs_iters
  45. else:
  46. epochs_iters = self.pdx_config.get_epochs_iters()
  47. if self.global_config.output is not None:
  48. self.pdx_config.update_save_dir(self.global_config.output)
  49. def get_train_kwargs(self) -> dict:
  50. """get key-value arguments of model training function
  51. Returns:
  52. dict: the arguments of training function.
  53. """
  54. train_args = {"device": self.get_device()}
  55. train_args["dy2st"] = self.train_config.get("dy2st", False)
  56. if self.global_config.output is not None:
  57. train_args["save_dir"] = self.global_config.output
  58. return train_args