当前位置: 首页>>代码示例>>Python>>正文


Python mxboard.SummaryWriter方法代码示例

本文整理汇总了Python中mxboard.SummaryWriter方法的典型用法代码示例。如果您正苦于以下问题:Python mxboard.SummaryWriter方法的具体用法?Python mxboard.SummaryWriter怎么用?Python mxboard.SummaryWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mxboard的用法示例。


在下文中一共展示了mxboard.SummaryWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot_mxboard

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def plot_mxboard(block, logdir='./logs'):
    """Plot network to visualize internal structures.

    Parameters
    ----------
    block : mxnet.gluon.HybridBlock
        A hybridizable network to be visualized.
    logdir : str
        The directory to save.

    """
    try:
        from mxboard import SummaryWriter
    except ImportError:
        print('mxboard is required. Please install via `pip install mxboard` ' +
              'or refer to https://github.com/awslabs/mxboard.')
        raise
    data = mx.sym.var('data')
    sym = block(data)
    if isinstance(sym, tuple):
        sym = mx.sym.Group(sym)
    with SummaryWriter(logdir=logdir) as sw:
        sw.add_graph(sym)
    usage = '`tensorboard --logdir={} --host=127.0.0.1 --port=8888`'.format(logdir)
    print('Log saved. Use: {} to visualize it'.format(usage)) 
开发者ID:dmlc,项目名称:gluon-cv,代码行数:27,代码来源:network.py

示例2: create_logger

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def create_logger(self):
        """
        Create the logger including the file log and summary log
        :return: logger and summary writer
        """
        if self.args.training:
            logger = Logger(self.args.log, '%s-%s' % (self.args.method, self.args.postfix),
                            rm_exist=self.args.start_epoch == 0)
            logger.update_dict(vars(self.args))

            if self.args.mxboard:
                from mxboard import SummaryWriter
                sw = SummaryWriter(logdir=self.args.log)
            else:
                sw = None
        else:
            logger, sw = None, None

        return logger, sw 
开发者ID:aws-samples,项目名称:d-SNE,代码行数:21,代码来源:training_sda.py

示例3: test_add_multiple_scalars

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def test_add_multiple_scalars():
    sw = SummaryWriter(logdir=_LOGDIR)
    sw.add_scalar(tag='test_multiple_scalars', value=np.random.uniform(), global_step=0)
    sw.add_scalar(tag='test_multiple_scalars', value=('scalar1', np.random.uniform()), global_step=0)
    sw.add_scalar(tag='test_multiple_scalars', value=['scalar2', np.random.uniform()], global_step=0)
    sw.add_scalar(tag='test_multiple_scalars',
                  value={'scalar3': np.random.uniform(), 'scalar4': np.random.uniform()},
                  global_step=0)
    items = os.listdir(_LOGDIR)
    assert len(items) == 2
    assert 'test_multiple_scalars' in items
    items.remove('test_multiple_scalars')
    assert items[0].startswith(_EVENT_FILE_PREFIX)
    print(items[0])
    assert file_exists(os.path.join(_LOGDIR, items[0]))

    named_scalar_dir = os.path.join(_LOGDIR, 'test_multiple_scalars')
    assert dir_exists(named_scalar_dir)
    for i in range(1, 5):
        sub_dir = os.path.join(named_scalar_dir, 'scalar%d' % i)
        assert dir_exists(sub_dir)
        sub_items = os.listdir(sub_dir)
        assert len(sub_items) == 1
        assert sub_items[0].startswith(_EVENT_FILE_PREFIX) 
开发者ID:awslabs,项目名称:mxboard,代码行数:26,代码来源:test_logging.py

示例4: test_add_embedding

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def test_add_embedding():
    def check_add_embedding(embedding, images=None, labels=None, global_step=None):
        with SummaryWriter(logdir=_LOGDIR) as sw:
            sw.add_embedding(tag='test_add_embedding', embedding=embedding, labels=labels,
                             images=images, global_step=global_step)
        check_and_remove_for_embedding('test_add_embedding', images=images,
                                       labels=labels, global_step=global_step)

    batch_size = 10
    embedding = mx.nd.uniform(shape=(batch_size, 20))
    labels = mx.nd.uniform(low=1, high=2, shape=(batch_size,)).astype('int32')
    images = mx.nd.uniform(shape=(batch_size, 3, 10, 10))
    global_step = np.random.randint(low=0, high=999999)

    check_add_embedding(embedding, labels=labels, images=images, global_step=global_step)
    check_add_embedding(embedding.asnumpy(), labels=labels, images=images, global_step=global_step)
    check_add_embedding(embedding, labels=labels.asnumpy(), images=images, global_step=global_step)
    check_add_embedding(embedding, labels=labels.asnumpy(), images=images.asnumpy(), global_step=global_step)
    check_add_embedding(embedding, labels=labels.asnumpy().tolist(), images=images, global_step=global_step)
    check_add_embedding(embedding, images=images, global_step=global_step)
    check_add_embedding(embedding, labels=labels, global_step=global_step)
    check_add_embedding(embedding, labels=labels.asnumpy(), global_step=global_step)
    check_add_embedding(embedding, labels=labels.asnumpy().tolist(), global_step=global_step)
    check_add_embedding(embedding, global_step=global_step)
    check_add_embedding(embedding) 
开发者ID:awslabs,项目名称:mxboard,代码行数:27,代码来源:test_logging.py

示例5: __init__

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def __init__(self, logging_dir, prefix=None):
        self.prefix = prefix
        try:
            from mxboard import SummaryWriter
            self.summary_writer = SummaryWriter(logging_dir)
        except ImportError:
            logging.error('You can install mxboard via `pip install mxboard`.') 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:9,代码来源:tensorboard.py

示例6: evaluate

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def evaluate(model, ctx, ground_truth, test_loader,
             n_pred, mean, std, sw, step):
    '''
    evaluate model on testing set

    Parameters
    ----------
    ground_truth: np.ndarray,
                  shape is (num_of_samples, 1, n_pred, num_of_vertices)

    test_loader: gluon.data.DataLoader, contains x and y

    n_pred: int

    mean: int

    std: int

    sw: mxboard.SummaryWriter

    step: int

    '''

    predictions = predict(model, ctx, test_loader, n_pred).asnumpy()
    pred = utils.math_utils.z_inverse(predictions, mean, std)

    mape = utils.math_utils.masked_mape_np(ground_truth, pred, 0)
    mae = utils.math_utils.MAE(ground_truth, pred)
    rmse = utils.math_utils.RMSE(ground_truth, pred)

    sw.add_scalar(tag='MAPE', value=mape, global_step=step)
    sw.add_scalar(tag='MAE', value=mae, global_step=step)
    sw.add_scalar(tag='RMSE', value=rmse, global_step=step)

    print('step: {}, MAPE: {}, MAE: {}, RMSE: {}'.format(step, mape,
                                                         mae, rmse)) 
开发者ID:Davidham3,项目名称:STGCN,代码行数:39,代码来源:trainer.py

示例7: __init__

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def __init__(self,
                 logdir: str,
                 source_vocab: Optional[vocab.Vocab] = None,
                 target_vocab: Optional[vocab.Vocab] = None) -> None:
        self.logdir = logdir
        self.source_labels = vocab.get_ordered_tokens_from_vocab(source_vocab) if source_vocab is not None else None
        self.target_labels = vocab.get_ordered_tokens_from_vocab(target_vocab) if target_vocab is not None else None
        try:
            import mxboard
            logger.info("Logging training events for Tensorboard at '%s'", self.logdir)
            self._writer = mxboard.SummaryWriter(logdir=self.logdir, flush_secs=60, verbose=False)
        except ImportError:
            logger.info("mxboard not found. Consider 'pip install mxboard' to log events to Tensorboard.")
            self._writer = None 
开发者ID:awslabs,项目名称:sockeye,代码行数:16,代码来源:training.py

示例8: __init__

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def __init__(self, logging_dir, total_step=0, prefix=None):
        self.prefix = prefix
        self.step = total_step
        try:
            from mxboard import SummaryWriter
            self.summary_writer = SummaryWriter(logging_dir)
        except ImportError:
            logging.error(
                'You can install tensorboard via `pip install mxboard`.') 
开发者ID:happywu,项目名称:Sequence-Level-Semantics-Aggregation,代码行数:11,代码来源:callback.py

示例9: test_add_scalar

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def test_add_scalar():
    sw = SummaryWriter(logdir=_LOGDIR)
    sw.add_scalar(tag='test_add_scalar', value=np.random.uniform(), global_step=0)
    sw.close()
    check_event_file_and_remove_logdir() 
开发者ID:awslabs,项目名称:mxboard,代码行数:7,代码来源:test_logging.py

示例10: test_add_histogram

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def test_add_histogram():
    def check_add_histogram(data):
        sw = SummaryWriter(logdir=_LOGDIR)
        sw.add_histogram(tag='test_add_histogram', values=data, global_step=0, bins=100)
        sw.close()
        check_event_file_and_remove_logdir()

    shape = rand_shape_nd(4)
    data = mx.nd.random.normal(shape=shape)
    check_add_histogram(data)
    check_add_histogram(data.asnumpy()) 
开发者ID:awslabs,项目名称:mxboard,代码行数:13,代码来源:test_logging.py

示例11: test_add_image

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def test_add_image():
    def check_add_image(data):
        sw = SummaryWriter(logdir=_LOGDIR)
        sw.add_image(tag='test_add_image', image=data, global_step=0)
        sw.close()
        check_event_file_and_remove_logdir()

    shape = list(rand_shape_nd(4))
    shape[1] = 3
    shape = tuple(shape)
    data = mx.nd.random.normal(shape=shape).clip(0, 1)
    check_add_image(data)
    check_add_image(data.asnumpy())
    check_add_image(data.astype('float64'))
    check_add_image((data * 255).astype('uint8')) 
开发者ID:awslabs,项目名称:mxboard,代码行数:17,代码来源:test_logging.py

示例12: test_add_audio

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def test_add_audio():
    def check_add_audio(data):
        sw = SummaryWriter(logdir=_LOGDIR)
        sw.add_audio(tag='test_add_audio', audio=data)
        sw.close()
        check_event_file_and_remove_logdir()

    shape = (100,)
    data = mx.nd.random.uniform(-1, 1, shape=shape)
    check_add_audio(data)
    check_add_audio(data.asnumpy()) 
开发者ID:awslabs,项目名称:mxboard,代码行数:13,代码来源:test_logging.py

示例13: test_add_pr_curve

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def test_add_pr_curve():
    def check_add_pr_curve(labels, predictions, num_thresholds):
        with SummaryWriter(_LOGDIR) as sw:
            sw.add_pr_curve(tag='test_add_pr_curve', labels=labels, predictions=predictions, num_thresholds=num_threshodls)
        check_event_file_and_remove_logdir()

    shape = (100,)
    predictions = mx.nd.uniform(low=0.0, high=1.0, shape=shape)
    labels = mx.nd.uniform(low=0, high=2, shape=shape).astype('int32')
    num_threshodls = 100
    check_add_pr_curve(labels, predictions, num_threshodls)
    check_add_pr_curve(labels.asnumpy(), predictions, num_threshodls)
    check_add_pr_curve(labels.asnumpy(), predictions.asnumpy(), num_threshodls) 
开发者ID:awslabs,项目名称:mxboard,代码行数:15,代码来源:test_logging.py

示例14: test_add_graph_symbol

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def test_add_graph_symbol():
    data = mx.sym.Variable('data')
    conv = mx.sym.Convolution(data, kernel=(2, 2), num_filter=2)
    nodes = _get_nodes_from_symbol(conv)
    expected_nodes = [NodeDef(name='data', op='null'),
                      NodeDef(name='convolution0/convolution0_weight', op='null',
                              attr={'param': AttrValue(
                                  s='{ kernel :  (2, 2) ,  num_filter :  2 }'.encode(encoding='utf-8'))}),
                      NodeDef(name='convolution0/convolution0_bias', op='null',
                              attr={'param': AttrValue(
                                  s='{ kernel :  (2, 2) ,  num_filter :  2 }'.encode(encoding='utf-8'))}),
                      NodeDef(name='convolution0/convolution0', op='Convolution',
                              input=['data', 'convolution0/convolution0_weight', 'convolution0/convolution0_bias'],
                              attr={'param': AttrValue(
                                  s='{ kernel :  (2, 2) ,  num_filter :  2 }'.encode(encoding='utf-8'))})]
    # check _get_nodes_from_symbol
    for expected_node, node in zip(expected_nodes, nodes):
        assert expected_node == node

    # check _sym2pb
    expected_graph = GraphDef(node=expected_nodes, versions=VersionDef(producer=100))
    graph = _net2pb(conv)
    assert expected_graph == graph

    # check add_graph
    with SummaryWriter(logdir=_LOGDIR) as sw:
        sw.add_graph(conv)
    check_event_file_and_remove_logdir() 
开发者ID:awslabs,项目名称:mxboard,代码行数:30,代码来源:test_logging.py

示例15: test_evaluate

# 需要导入模块: import mxboard [as 别名]
# 或者: from mxboard import SummaryWriter [as 别名]
def test_evaluate(self):
        from model import hybrid_model
        from model import trainer
        from data_loader.data_utils import data_gen
        import numpy as np
        from mxboard import SummaryWriter
        import os
        import shutil

        ctx = mx.gpu(1)
        num_of_vertices = 897
        batch_size = 50

        PeMS_dataset = data_gen('datasets/PeMSD7_V_897.csv', 24)
        print('>> Loading dataset with Mean: {0:.2f}, STD: {1:.2f}'.format(
            PeMS_dataset.mean,
            PeMS_dataset.std
        ))

        test = PeMS_dataset['test'].transpose((0, 3, 1, 2))
        test_x, test_y = test[:100, :, : 12, :], test[:100, :, 12:, :]
        test_loader = gluon.data.DataLoader(
            gluon.data.ArrayDataset(nd.array(test_x), nd.array(test_y)),
            batch_size=batch_size,
            shuffle=False
        )
        print(test_x.shape, test_y.shape)

        cheb_polys = nd.random_uniform(shape=(num_of_vertices,
                                              num_of_vertices * 3))
        blocks = [[1, 32, 64], [64, 32, 128]]
        x = nd.random_uniform(shape=(batch_size, 1, 12, num_of_vertices),
                              ctx=ctx)

        net = hybrid_model.STGCN(12, 3, 3, blocks, 1.0,
                                 num_of_vertices, cheb_polys)
        net.initialize(ctx=ctx)
        net.hybridize()
        net(x)

        ground_truth = (np.concatenate([y.asnumpy() for x, y in test_loader],
                                       axis=0) *
                        PeMS_dataset.std +
                        PeMS_dataset.mean)[:100]

        if os.path.exists('test_logs'):
            shutil.rmtree('test_logs')
        sw = SummaryWriter('test_logs', flush_secs=5)

        trainer.evaluate(net, ctx, ground_truth, test_loader,
                         12, PeMS_dataset.mean, PeMS_dataset.std, sw, 0)
        self.assertEqual(os.path.exists('test_logs'), True)
        sw.close()
        if os.path.exists('test_logs'):
            shutil.rmtree('test_logs') 
开发者ID:Davidham3,项目名称:STGCN,代码行数:57,代码来源:training_test.py


注:本文中的mxboard.SummaryWriter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。