Logml API#
logml.logger#
Logger class.
- class Logger(n_epochs, n_batches, log_interval=1, name=None, *, styles='', sizes=6, average=None, silent=False, show_bar=True, show_time=True, bold_keys=False, name_style='')#
Bases:
objectLogger class. Handles int, float, str and bool values.
- Parameters:
n_epochs (int) – Number of epochs.
n_batches (Optional[int]) – Number of batches per epoch. Set to None if not available.
log_interval (int, optional) – Number of batches between each log. None for 4 update per second. By default 1.
name (Optional[str], optional) – Name of the logger. It will be display at the top of the logs. By default None (no name).
styles (Union[Dict, str], optional) – Default style of the values. Include color, bold, italic and more See https://rich.readthedocs.io/en/stable/style.html for more details. E.g. {‘loss’: ‘bold red’, ‘acc’: ‘italic #af00ff’} Use a single string to apply the same style to all values. These styles can also be set or overwritten in the log method. By default, use rich default style.
sizes (Union[Dict, int], optional) – Default sizes to display for each numerical values. Note that the dot is counted as a character. E.g. {‘loss’: 3, ‘acc’: 2}. Use a single int to apply the same size to all values. These numbers can also be set or overwritten in the log method. By default 6.
average (Optional[List[str]], optional) – Default list of the values to average over the epoch. This can also be overwritten in the log method. By default None.
silent (bool, optional) – Whether to print the logs or not. By default False.
show_bar (bool, optional) – Whether to show the progress bar or not. By default True.
show_time (bool, optional) – Whether to show the time or not. By default True.
bold_keys (bool, optional) – Whether to bold the key or not. By default False.
name_style (str, optional) – Style of the name. By default, use the rich default style.
Examples
logger = Logger(n_epochs=10, n_batches=100) for _ in range(10): for _ in logger.tqdm(range(100)): logger.log(loss=0.5, acc=0.9)
Attribute#
- stepint
Number of batches seen since the beginning.
- current_epochint
Current epoch number (starting at 1).
- current_batchint
Current batch number (starting at 1).
- valsDict[str, VarType]
Last values called inside log (not averaged nor resized).
- mean_valsDict[str, VarType]
Current mean values (only numerical values).
- log(values=None, *, message='', styles=None, sizes=None, average=None)#
Log the values with style.
- Parameters:
values (Dict[str, Any] | None) – Values to log. E.g. {‘loss’: 0.1, ‘acc’: 0.9}
message (str, optional) – Message to display at the end of the log. By default empty.
styles (Union[Dict, str, None], optional) –
Style of the values. Include color, bold, italic and more See https://rich.readthedocs.io/en/stable/style.html for more details. E.g.:
{'loss': 'bold red', 'acc': 'italic #af00ff'}
Use a single string to apply the same style to all values. By default None (use the default style).
sizes (Union[Dict, int], optional) –
Size of the values to display for each numerical values. E.g.:
{'loss': 7, 'acc': 2}
Use a single int to apply the same size to all values. By default None (use the default style).
average (Optional[List[str]], optional) – List of the values to average over the epoch. None to not average. By default None.
- Return type:
- tqdm(iterable, *, reset_means=True)#
Browse an iterable dataset and automatically update the epoch and batch.
No need to explicitly call
new_epoch()ornew_batch()as they are automatically called. Ifn_batchesis not specified and the iterable implement a __len__ attribute, the number of batch is inferred and store inn_batches.
- new_epoch(*, reset_means=True)#
Declare a new epoch.
- start_epoch(*, reset_means=True)#
Declare a new epoch. Alias for
new_epoch().- Return type:
- start_batch()#
Declare a new batch. Alias for
new_batch().- Return type:
- detach(*, skipline=True)#
Stop the live display.
Stop the live display while keeping the current display visible in the terminal. :rtype:
None
- stop()#
Stop the live display.
Stop the live display while keeping the current display visible in the terminal. Alias for
detach()with skipline=False. :rtype:None
- get_vals(*, average=None)#
Get the last values called with log, optionally averaged.
logml.time_utils#
Utilities for time data.
- get_time_range(current_time, start_glob, start_epoch, current_epoch, current_batch, n_epochs, n_batches)#
Get delta and eta times for global and epoch.
- Parameters:
current_time (float) – Current time in seconds.
start_glob (float) – Global starting time in seconds.
start_epoch (float) – Epoch starting time in seconds. None if not available.
current_epoch (int, optional) – Current epoch (starting at 1). None if not available.
current_batch (int, optional) – Current batch (starting at 1). None if not available.
n_epochs (int, optional) – Number of epochs. None if not available.
n_batches (Optional[int], optional) – Number of batches per epoch. None if not available. By default None.
- Raises:
ValueError – If current_batch, current_epoch, n_epochs or n_batch are 0.
- Return type:
- Returns:
delta_glob (float) – Delta time since global start in seconds.
delta_epoch (float) – Delta time since epoch start in seconds. None if unavailable.
eta_glob (Optional[float]) – Estimated time until global end in seconds. None if unavailable.
eta_epoch (Optional[float]) – Estimated time until epoch end in seconds. None if unavailable.