Python tensorboard_logger.Logger() Examples

The following are 9 code examples of tensorboard_logger.Logger(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorboard_logger , or try the search function .
Example #1
Source File: pretraining.py    From DCC with MIT License 5 votes vote down vote up
def main(args):
    datadir = get_data_dir(args.db)
    outputdir = get_output_dir(args.db)

    logger = None
    if args.tensorboard:
        # One should create folder for storing logs
        loggin_dir = os.path.join(outputdir, 'runs', 'pretraining')
        if not os.path.exists(loggin_dir):
            os.makedirs(loggin_dir)
        loggin_dir = os.path.join(loggin_dir, '%s' % (args.id))
        if args.clean_log:
            remove_files_in_dir(loggin_dir)
        logger = Logger(loggin_dir)

    use_cuda = torch.cuda.is_available()

    # Set the seed for reproducing the results
    random.seed(args.manualSeed)
    np.random.seed(args.manualSeed)
    torch.manual_seed(args.manualSeed)
    if use_cuda:
        torch.cuda.manual_seed_all(args.manualSeed)
        torch.backends.cudnn.enabled = True
        cudnn.benchmark = True

    kwargs = {'num_workers': 0, 'pin_memory': True} if use_cuda else {}
    trainset = DCCPT_data(root=datadir, train=True, h5=args.h5)
    testset = DCCPT_data(root=datadir, train=False, h5=args.h5)

    nepoch = int(np.ceil(np.array(args.niter * args.batchsize, dtype=float) / len(trainset)))
    step = int(np.ceil(np.array(args.step * args.batchsize, dtype=float) / len(trainset)))

    trainloader = torch.utils.data.DataLoader(trainset, batch_size=args.batchsize, shuffle=True, **kwargs)
    testloader = torch.utils.data.DataLoader(testset, batch_size=100, shuffle=True, **kwargs)

    return pretrain(args, outputdir, {'nlayers':4, 'dropout':0.2, 'reluslope':0.0,
                       'nepoch':nepoch, 'lrate':[args.lr], 'wdecay':[0.0], 'step':step}, use_cuda, trainloader, testloader, logger) 
Example #2
Source File: test_tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def test_smoke_logger(tmpdir):
    logger = Logger(str(tmpdir), flush_secs=0.1)
    for step in range(10):
        logger.log_value('v1', step * 1.5, step)
        logger.log_value('v2', step ** 1.5 - 2)
    time.sleep(0.5)
    tf_log, = tmpdir.listdir()
    assert tf_log.basename.startswith('events.out.tfevents.') 
Example #3
Source File: test_tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def test_serialization(tmpdir):
    logger = Logger(str(tmpdir), flush_secs=0.1, dummy_time=256.5)
    logger.log_value('v/1', 1.5, 1)
    logger.log_value('v/22', 16.0, 2)
    time.sleep(0.5)
    tf_log, = tmpdir.listdir()
    assert tf_log.read_binary() == (
        # step = 0, initial record
        b'\x18\x00\x00\x00\x00\x00\x00\x00\xa3\x7fK"\t\x00\x00\x00\x00\x00\x08p@\x1a\rbrain.Event:2\xbc\x98!+'
        # v/1
        b'\x19\x00\x00\x00\x00\x00\x00\x00\x8b\xf1\x08(\t\x00\x00\x00\x00\x00\x08p@\x10\x01*\x0c\n\n\n\x03v/1\x15\x00\x00\xc0?,\xec\xc0\x87'
        # v/22
        b'\x1a\x00\x00\x00\x00\x00\x00\x00\x12\x9b\xd8-\t\x00\x00\x00\x00\x00\x08p@\x10\x02*\r\n\x0b\n\x04v/22\x15\x00\x00\x80A\x8f\xa3\xb6\x88'
    ) 
Example #4
Source File: test_tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def test_dummy():
    logger = Logger(None, is_dummy=True)
    for step in range(3):
        logger.log_value('A v/1', step, step)
        logger.log_value('A v/2', step * 2, step)
    assert dict(logger.dummy_log) == {
        'A_v/1': [(0, 0), (1, 1), (2, 2)],
        'A_v/2': [(0, 0), (1, 2), (2, 4)],
    } 
Example #5
Source File: test_tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def test_unique():
    logger = Logger(None, is_dummy=True)
    for step in range(1, 3):
        # names that normalize to the same valid name
        logger.log_value('A v/1', step, step)
        logger.log_value('A\tv/1', step * 2, step)
        logger.log_value('A  v/1', step * 3, step)
    assert dict(logger.dummy_log) == {
        'A_v/1':   [(1, 1), (2, 2)],
        'A_v/1/1': [(1, 2), (2, 4)],
        'A_v/1/2': [(1, 3), (2, 6)],
    } 
Example #6
Source File: test_tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def test_dummy_histo():
    logger = Logger(None, is_dummy=True)
    bins = [0, 1, 2, 3]
    logger.log_histogram('key', (bins, [0.0, 1.0, 2.0]), step=1)
    logger.log_histogram('key', (bins, [1.0, 1.5, 2.5]), step=2)
    logger.log_histogram('key', (bins, [0.0, 1.0, 2.0]), step=3)

    assert dict(logger.dummy_log) == {
        'key': [(1, (bins, [0.0, 1.0, 2.0])),
                (2, (bins, [1.0, 1.5, 2.5])),
                (3, (bins, [0.0, 1.0, 2.0]))]} 
Example #7
Source File: test_tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def test_real_histo_data(tmpdir):
    logger = Logger(str(tmpdir), flush_secs=0.1)
    logger.log_histogram('hist2', [1, 7, 6, 9, 8, 1, 4, 5, 3, 7], step=1)
    logger.log_histogram('hist2', [5, 3, 2, 0, 8, 5, 7, 7, 7, 2], step=2)
    logger.log_histogram('hist2', [1, 2, 2, 1, 5, 1, 8, 4, 4, 1], step=3)
    tf_log, = glob.glob(str(tmpdir) + '/*')
    assert os.path.basename(tf_log).startswith('events.out.tfevents.') 
Example #8
Source File: test_tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def test_dummy_images():
    logger = Logger(None, is_dummy=True)
    img = np.random.rand(10, 10)
    images = [img, img]
    logger.log_images('key', images, step=1)
    logger.log_images('key', images, step=2)
    logger.log_images('key', images, step=3)

    assert dict(logger.dummy_log) == {
        'key': [(1, images),
                (2, images),
                (3, images)]} 
Example #9
Source File: test_tensorboard_logger.py    From tensorboard_logger with MIT License 5 votes vote down vote up
def test_real_image_data(tmpdir):
    logger = Logger(str(tmpdir), flush_secs=0.1)
    img = np.random.rand(10, 10)
    images = [img, img]
    logger.log_images('key', images, step=1)
    logger.log_images('key', images, step=2)
    logger.log_images('key', images, step=3)
    tf_log, = glob.glob(str(tmpdir) + '/*')
    assert os.path.basename(tf_log).startswith('events.out.tfevents.')