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