Tracker

Github Open In Colab

Here you specify indicators and the logger stores them temporarily and write in batches. It can aggregate and write them as means or histograms.

%%capture
!pip install labml
import time

import numpy as np

from labml import tracker

# dummy train function
def train():
    return np.random.randint(100)

# Reset global step because we incremented in previous loop
tracker.set_global_step(0)

This stores all the loss values and writes the logs the mean on every tenth iteration. Console output line is replaced until labml.tracker.new_line() is called.

for i in range(1, 401):
    tracker.add_global_step()
    loss = train()
    tracker.add(loss=loss)
    if i % 10 == 0:
        tracker.save()
    if i % 100 == 0:
        tracker.new_line()
    time.sleep(0.02)
     100:   loss:  45.1000
     200:   loss:  60.9000
     300:   loss:  61.1000
     400:   loss:  55.6000

Indicator settings

# dummy train function
def train2(idx):
    return idx, 10, np.random.randint(100)

# Reset global step because we incremented in previous loop
tracker.set_global_step(0)

Histogram indicators will log a histogram of data. Queue will store data in a deque of size queue_size, and log histograms. Both of these will log the means too. And if is_print is True it will print the mean.

queue size of 10 and the values are printed to the console

tracker.set_queue('reward', 10, True)

By default values are not printed to console; i.e. is_print defaults to False.

tracker.set_scalar('policy')

Settings is_print to True will print the mean value of histogram to console

tracker.set_histogram('value', True)
for i in range(1, 400):
    tracker.add_global_step()
    reward, policy, value = train2(i)
    tracker.add(reward=reward, policy=policy, value=value, loss=1.)
    if i % 10 == 0:
        tracker.save()
    if i % 100 == 0:
        tracker.new_line()
     100:   loss:   1.0000 reward:  95.5000 value:  45.2000
     200:   loss:  1.00000 reward:  195.500 value:  61.0000
     300:   loss:  1.00000 reward:  295.500 value:  60.3000
     390:   loss:  1.00000 reward:  385.500 value:  57.7000