Logger¶
%%capture
!pip install labml
from labml import logger
from labml.logger import Text, Color
You can log to the screen with log()
.
Logging with colors¶
logger.log("Colors are missing when viewed on github", Text.highlight)
Colors are missing when viewed on github
You can use predifined styles
logger.log([
('Styles ', Text.heading),
('Danger ', Text.danger),
('Warning ', Text.warning),
('Meta ', Text.meta),
('Key ', Text.key),
('Meta2 ', Text.meta2),
('Title ', Text.title),
('Heading ', Text.heading),
('Value ', Text.value),
('Highlight ', Text.highlight),
('Subtle', Text.subtle)
])
Styles Danger Warning Meta Key Meta2 Title Heading Value Highlight Subtle
Or, specify colors
logger.log([
('Colors ', Text.heading),
('Red ', Color.red),
('Black ', Color.black),
('Blue ', Color.blue),
('Cyan ', Color.cyan),
('Green ', Color.green),
('Orange ', Color.orange),
('Purple Heading ', [Color.purple, Text.heading]),
('White', Color.white),
])
Colors Red Black Blue Cyan Green Orange Purple Heading White
Logging debug info¶
You can pretty print python objects with inspect()
.
logger.inspect(a=2, b=1)
a: 2 b: 1
logger.inspect(dict(name='Name', price=22))
name: "Name" price: 22 Total 2 item(s)
Log PyTorch tensors and NumPy arrays
import torch
torch_tensor = torch.arange(0, 100).view(10, 10)
logger.inspect(torch_tensor)
dtype: torch.int64 shape: [10, 10] min: 0 max: 99 mean: 49.5000 std: 29.0115 [ [0, 1, 2, ..., 9 ], [10, 11, 12, ..., 19 ], [20, 21, 22, ..., 29 ], ..., [90, 91, 92, ..., 99 ] ]
numpy_array = torch_tensor.numpy()
logger.inspect(numpy_array)
dtype: int64 shape: [10, 10] min: 0 max: 99 mean: 49.5000 std: 28.8661 [ [0, 1, 2, ..., 9 ], [10, 11, 12, ..., 19 ], [20, 21, 22, ..., 29 ], ..., [90, 91, 92, ..., 99 ] ]