Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/percevalw/rich-logger
Table logger using Rich
https://github.com/percevalw/rich-logger
Last synced: 3 months ago
JSON representation
Table logger using Rich
- Host: GitHub
- URL: https://github.com/percevalw/rich-logger
- Owner: percevalw
- License: bsd-3-clause
- Created: 2021-02-05T14:18:06.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-31T19:41:00.000Z (over 1 year ago)
- Last Synced: 2024-11-01T19:52:32.759Z (4 months ago)
- Language: Python
- Homepage:
- Size: 505 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

[](https://pypi.org/project/rich-logger)# rich-logger
Table logger using Rich, aimed at Pytorch Lightning logging## Features
- display your training logs with pretty [rich](https://github.com/willmcgugan/rich) tables
- describe your fields with `goal` ("higher_is_better" or "lower_is_better"), `format` and `name`
- a field descriptor can be matched with any regex
- a field name can be computed as a regex substitution
- works in Jupyter notebooks as well as in a command line
- integrates easily with [Pytorch Lightning](https://github.com/PyTorchLightning/pytorch-lightning)## Demo
```python
from rich_logger import RichTablePrinter
import time
import random
from tqdm import trangelogger_fields = {
"step": {},
"(.*)_precision": {
"goal": "higher_is_better",
"format": "{:.4f}",
"name": r"\1_p",
},
"(.*)_recall": {
"goal": "higher_is_better",
"format": "{:.4f}",
"name": r"\1_r",
},
"duration": {"format": "{:.1f}", "name": "dur(s)"},
".*": True, # Any other field must be logged at the end
}def optimization():
printer = RichTablePrinter(key="step", fields=logger_fields)
printer.hijack_tqdm()t = time.time()
for i in trange(10):
time.sleep(random.random() / 3)
printer.log(
{
"step": i,
"task_precision": i / 10.0 if i < 5 else 0.5 - (i - 5) / 10.0,
}
)
time.sleep(random.random() / 3)
printer.log(
{
"step": i,
"task_recall": 0.0 if i < 3 else (i - 3) / 10.0,
"duration": time.time() - t,
}
)
printer.log({"test": i})
t = time.time()
for j in trange(5):
time.sleep(random.random() / 10)printer.finalize()
optimization()
```
## Use it with PytorchLightning
```python
from rich_logger import RichTableLoggertrainer = pl.Trainer(..., logger=[RichTableLogger(key="epoch", fields=logger_fields)])
```