trainer.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 ..image_classification import ClsTrainer
  15. from .model_list import MODELS
  16. class ShiTuRecTrainer(ClsTrainer):
  17. """ShiTu Recognition Model Trainer"""
  18. entities = MODELS
  19. def update_config(self):
  20. """update training config"""
  21. if self.train_config.log_interval:
  22. self.pdx_config.update_log_interval(self.train_config.log_interval)
  23. if self.train_config.eval_interval:
  24. self.pdx_config.update_eval_interval(self.train_config.eval_interval)
  25. if self.train_config.save_interval:
  26. self.pdx_config.update_save_interval(self.train_config.save_interval)
  27. self.pdx_config.update_dataset(
  28. self.global_config.dataset_dir, "ShiTuRecDataset"
  29. )
  30. if self.train_config.num_classes is not None:
  31. self.pdx_config.update_num_classes(self.train_config.num_classes)
  32. if self.train_config.pretrain_weight_path != "":
  33. self.pdx_config.update_pretrained_weights(
  34. self.train_config.pretrain_weight_path
  35. )
  36. if self.train_config.batch_size is not None:
  37. self.pdx_config.update_batch_size(self.train_config.batch_size)
  38. if self.train_config.learning_rate is not None:
  39. self.pdx_config.update_learning_rate(self.train_config.learning_rate)
  40. if self.train_config.epochs_iters is not None:
  41. self.pdx_config._update_epochs(self.train_config.epochs_iters)
  42. if self.train_config.warmup_steps is not None:
  43. self.pdx_config.update_warmup_epochs(self.train_config.warmup_steps)
  44. if self.global_config.output is not None:
  45. self.pdx_config._update_output_dir(self.global_config.output)