Helper class to log information. The class implements a universal logger that can push information to - local shell - tensorboard To support a multi-thread environment, it includes the rank of the current thread in the logging. Usage: .. code-block:: python
| 205 | |
| 206 | |
| 207 | class Logger: |
| 208 | """Helper class to log information. |
| 209 | |
| 210 | The class implements a universal logger that can push information to |
| 211 | - local shell |
| 212 | - tensorboard |
| 213 | |
| 214 | To support a multi-thread environment, it includes the rank of the current thread |
| 215 | in the logging. |
| 216 | |
| 217 | Usage: |
| 218 | |
| 219 | .. code-block:: python |
| 220 | |
| 221 | # create logger |
| 222 | logger = Logger( |
| 223 | log_filename=os.path.join('log', f'log_rank{rank}.txt'), |
| 224 | tensorboard_dir=os.path.join('tensorboard', f'rank{rank}'), |
| 225 | open_tensorboard=True, |
| 226 | tensorboard_port=22222, |
| 227 | rank=rank, |
| 228 | ) |
| 229 | |
| 230 | for iter in range(max_iter): |
| 231 | # some random scalars |
| 232 | loss_val1 = 123. |
| 233 | loss_val2 = 456. |
| 234 | |
| 235 | # log loss |
| 236 | logger.add_scalars( |
| 237 | main_tag='train', |
| 238 | tag_scalar_dict={'loss_name1': loss_val1, 'loss_name2': loss_val2}, |
| 239 | epoch=epoch, |
| 240 | batch_idx=batch_idx, |
| 241 | global_step=global_step, |
| 242 | ) |
| 243 | |
| 244 | # remember to flush the logger every iteration |
| 245 | logger.flush() |
| 246 | |
| 247 | # remember to close the logger |
| 248 | logger.close() |
| 249 | """ |
| 250 | |
| 251 | def __init__( |
| 252 | self, |
| 253 | log_filename=None, |
| 254 | tensorboard_dir=None, |
| 255 | tensorboard_num_history_figures=100, |
| 256 | tensorboard_max_reload_threads=1, |
| 257 | tensorboard_exe_path="/venv/bin/tensorboard", |
| 258 | open_tensorboard=False, |
| 259 | tensorboard_port=22222, |
| 260 | rank=0, |
| 261 | launch_tensorboard_at_parent_dir: bool = True, |
| 262 | ): |
| 263 | """Create the logger. |
| 264 |