1234567891011121314151617181920212223242526272829303132333435363738 |
- # -*- coding: utf-8 -*-
- """
- @author: yq
- @time: 2024/11/1
- @desc: 模型训练超参数配置类
- """
- import json
- import os
- from commom import GeneralException
- from enums import ResultCodesEnum
- class TrainConfigEntity():
- def __init__(self, lr: float):
- # 学习率
- self._lr = lr
- @property
- def lr(self):
- return self._lr
- @staticmethod
- def from_config(config_path: str):
- """
- 从配置文件生成实体类
- """
- if os.path.exists(config_path):
- with open(config_path, mode="r", encoding="utf-8") as f:
- j = json.loads(f.read())
- else:
- raise GeneralException(ResultCodesEnum.NOT_FOUND, message=f"指配置文件【{config_path}】不存在")
- return TrainConfigEntity(**j)
- if __name__ == "__main__":
- pass
|