trainer.py 2.5 KB

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