log
Module diagram
classDiagram
class log {
}
class dashboard {
}
class log_handler {
}
class logger {
}
class string_formatter {
}
log_handler --> dashboard
log_handler --> logger
log
결과 로그 및 실험 환경 정보를 저장하기 위한 LogHandler 클래스를 제공합니다.
dashboard
Dashboard
Bases: Registerable
Source code in SaigeToolkit/log/dashboard.py
Tensorboard
Bases: Dashboard
Source code in SaigeToolkit/log/dashboard.py
tensorboard_writer
instance-attribute
log
Source code in SaigeToolkit/log/dashboard.py
log_handler
LogHandler
LogHandler(name: str = 'SaigeResearch', logdir: Optional[str] = None, add_time_to_logdir: bool = False, logfile: Optional[str] = None, stdout: bool = False, level: str = 'INFO', formatter: str = f'%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s', dashboard: Optional[Dict] = None)
Source code in SaigeToolkit/log/log_handler.py
logger
instance-attribute
logger = configure_logger(name=name, level=level, formatter=formatter, path=logfile_path, stdout=stdout)
log_dashboard
skip_if_logdir_is_none
Decorator to skip the method if logdir is None.
Source code in SaigeToolkit/log/log_handler.py
save_json
Save the data in the {self.logdir}/{json_path}.
Parameters:
-
data(Dict) –data to save
-
json_path(str, default:'log.json') –json path. Defaults to "log.json".
Source code in SaigeToolkit/log/log_handler.py
save_image
Save the image in the {self.logdir}/{file_path}.
Source code in SaigeToolkit/log/log_handler.py
save_code
save_code(target_file: str, directory: str = 'source_code', relative_path: Optional[str] = None) -> None
target_file을 실행하는데 필요한 모든 코드를 "source_code" 디렉토리에 저장합니다.
Parameters:
-
target_file(str) –target_file path
-
directory(str, default:'source_code') –save directory. Defaults to "source_code".
-
relative_path(Optional[str], default:None) –relative path of the target file from the module(main.py). Defaults to None.
Caution
target_file의 경로에 "."이 포함되어 있으면 제대로 작동하지 않습니다.
Usage
1) module과 같은 레벨의 실행 파일에서 소스 코드 저장을 위해 다음과 같이 사용할 수 있습니다.
ex) python run.py 로 실행하고 run.py에서 ./script/train.py의 train 함수를 호출하는 경우
``` python
import __main__
from ..SaigeToolkit.SaigeToolkit.util.log_handler import LogHandler
def train(..., log_handler, ...):
...
log_handler = LogHandler(**log_handler)
log_handler.save_code(__main__.__file__)
```
2) module보다 하위 디렉토리에 있는 실행 파일에서 소스 코드 저장을 위해 다음과 같이 사용할 수 있습니다.
ex) python experiment/test.py로 실행하는 경우.
``` python
import __main__
def test(...):
...
log_handler = LogHandler(**log_handler)
log_handler.save_code(__main__.__file__, relative_path="experiment")
```
Source code in SaigeToolkit/log/log_handler.py
save_yaml
Save the dict in yaml format.
Parameters:
-
data(Dict) –Dict to save
-
filename(str) –filename
Source code in SaigeToolkit/log/log_handler.py
save_source_info
Save current time (KST) + git info + run command in "source_info.json".
Parameters:
-
git_root_dir(str) –.git디렉토리가 위치한 상위 디렉토리 경로.
Source code in SaigeToolkit/log/log_handler.py
save_checkpoint
Save checkpoint in the "checkpoint" directory.
Parameters:
-
trainer(Trainer) –An instance containing information to be saved in the checkpoint.
-
filename(str) –filename
-
password(Optional[str], default:None) –Password for checkpoint file. Defaults to None.
Source code in SaigeToolkit/log/log_handler.py
get_time_string
staticmethod
logger
configure_logger
configure_logger(name: Optional[str] = 'SaigeResearch', level: str = 'INFO', formatter: str = f'%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s', path: Optional[str] = None, stdout: bool = False)
Source code in SaigeToolkit/log/logger.py
string_formatter
list_to_pretty_string
list_to_pretty_string(list_of_number: List[Union[int, float]], row_name: str = None, each_length: int = 10, indent: int = 12) -> str
list of Union[int, float] string으로 바꾸는 함수입니다. each_length의 길이가 되도록 " "를 늘려줍니다. log 예시:
Args: list_of_number (List[Union[int, float]]): 숫자가 들어있는 list입니다. row_name (str, optional): 각 row의 이름을 넣어줍니다. Defaults to None. each_length (int, optional): 각 원소마다 가지는 길이. Defaults to 10. indent (int, optional): indentation. Defaults to 12.Returns: str
Source code in SaigeToolkit/log/string_formatter.py
confusion_matrix_to_pretty_string
confusion_matrix_to_pretty_string(confusion_matrix: List[List[Union[int, float]]], each_length: int = 10, indent: int = 12) -> str
confusion matrix를 logging하기 위해 string으로 바꾸는 함수입니다. each_length의 길이가 되도록 " "를 늘려줍니다. log 예시:
...
2023-xx-xx xx:yy:zz,000 INFO [train.py:143]
object/confusion_matrix:
| class 0| class 1| class 2|
class 0| 0| 132| 123|
class 1| 1| 458| 8394|
class 2| 10| 1| 2|
object/accuracy: 0.0000
...
Returns: str