Logging MXNet data for visualization in TensorBoard.

Overview

Logging MXNet Data for Visualization in TensorBoard

Overview

MXBoard provides a set of APIs for logging MXNet data for visualization in TensorBoard. The idea of this project comes from discussions with Zihao Zheng, the author of dmlc/tensorboard, on delivering a visualization solution for MXNet users. We aim at providing the logging APIs that can process MXNet data efficiently and supporting most of the data types for visualization in the TensorBoard GUI. We adapted the following low-level logging components from their Python and C++ implementations in TensorFlow: FileWriter, EventFileWriter, EventsWriter, RecordWriter, and _EventLoggerThread. We also adapted the user-level logging APIs defined in SummaryWriter from tensorboard-pytorch. The encoding algorithm used in writing protobuf objects into event files is directly borrowed from TeamHG-Memex/tensorboard_logger.

MXBoard supports a set of Python APIs for logging the following data types for TensorBoard to render. Logging APIs for other languages may be added in the future.

mxboard_cover

The corresponding Python APIs are accessible through a class called SummaryWriter as follows:

    mxboard.SummaryWriter.add_graph
    mxboard.SummaryWriter.add_scalar
    mxboard.SummaryWriter.add_histogram
    mxboard.SummaryWriter.add_embedding
    mxboard.SummaryWriter.add_image
    mxboard.SummaryWriter.add_text
    mxboard.SummaryWriter.add_pr_curve
    mxboard.SummaryWriter.add_audio

Installation

Install MXBoard from PyPI

pip install mxboard

Install MXBoard Python package from source

git clone https://github.com/awslabs/mxboard.git
cd mxboard/python
python setup.py install

Install TensorBoard from PyPI

MXBoard is a logger for writing MXNet data to event files. To visualize those data in browsers, users still have to install TensorBoard separately.

pip install tensorboard

Use the following to verify that the TensorBoard binary has been installed correctly.

tensorboard --help

Other required packages

MXBoard relies on the following packages for data logging.

Please note that you need to install MXNet manually before using MXBoard. The other packages will be installed automatically when you install MXBoard via pip or building from source. If you want to build from source, please make sure that protobuf compiler is installed. Check this page for downloading the protobuf compiler whose file name starts with "protoc".

Visualizing MXNet data in 30 seconds

Now that you have installed all of the required packages, let's walk through a simple visualization example. You will see how MXBoard enables visualizing MXNet NDArrays with histograms.

Step 1. Logging event data to a file.

Prepare a Python script for writing data generated by the normal operator to an event file. The data is generated ten times with decreasing standard deviation and written to the event file each time. It's expected to see the data distribution gradually become more centered around the mean value. Note that here we specify creating the event file in the folder logs under the current directory. We will need to pass this folder path to the TensorBoard binary.

import mxnet as mx
from mxboard import SummaryWriter


with SummaryWriter(logdir='./logs') as sw:
    for i in range(10):
        # create a normal distribution with fixed mean and decreasing std
        data = mx.nd.normal(loc=0, scale=10.0/(i+1), shape=(10, 3, 8, 8))
        sw.add_histogram(tag='norml_dist', values=data, bins=200, global_step=i)

Step 2. Launch TensorBoard to load the event file generated above.

Use the following command to start the TensorBoard server. It will use the logs that were generated in the current directory's logs folder.

tensorboard --logdir=./logs --host=127.0.0.1 --port=8888

Note that in some situations, the port number 8888 may be occupied by other applications and launching TensorBoard may fail. You may choose a different available port number.

Step 3. Open TensorBoard in your browser.

In the browser, enter the address 127.0.0.1:8888, and click the tab HISTOGRAMS in the TensorBoard GUI. You will see data distribution changing as time progresses.

summary_histogram_norm

More tutorials

References

  1. https://github.com/TeamHG-Memex/tensorboard_logger
  2. https://github.com/lanpa/tensorboard-pytorch
  3. https://github.com/dmlc/tensorboard
  4. https://github.com/tensorflow/tensorflow
  5. https://github.com/tensorflow/tensorboard

License

This library is licensed under the Apache 2.0 License.

Comments
  • No handlers could be found for logger

    No handlers could be found for logger "mxboard.event_file_writer"

    Hello, i install mxboard and run the demo py, but raise errors:

    No handlers could be found for logger "mxboard.event_file_writer"

    my conda list is as follows: mxboard 0.1.0 mxnet 1.2.0 tensorboard 1.12.0 tensorflow 1.12.0

    how can i solve this, thank u very much!

    bug 
    opened by HarveyGuo960817 8
  • add_embedding() does not support a list of strings as labels

    add_embedding() does not support a list of strings as labels

    The documentation states that sw.add_embedding() can take a list of elements, convertible to string as an argument to the labels parameter. However, the code prevents this both in add_embedding() and in _make_metadata_tsv() by throwing an error if labels is a List and not NDArray or NPArray.

    bug 
    opened by fhieber 7
  • fix: forcing make_image_grid to generate square sprite image

    fix: forcing make_image_grid to generate square sprite image

    Issues, if available: #35

    Description of changes: one line changed in utils/make_image_grid to make sure the produced sprite image is precisely square

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    opened by YusongLeng 5
  • Import error

    Import error

    After pip install mxboard, when I import mxboard, it errors:

    `import mxboard as mb TypeError Traceback (most recent call last) in () ----> 1 import mxboard as mb

    /home/users/nn/code/py/mxnet/python/mxboard/init.py in () 19 20 from future import absolute_import ---> 21 from .writer import SummaryWriter 22 23 version = '0.1.0'

    /home/users/nn/code/py/mxnet/python/mxboard/writer.py in () 26 import os 27 import logging ---> 28 from .proto import event_pb2 29 from .proto import summary_pb2 30 from .event_file_writer import EventFileWriter

    /home/users/nn/code/py/mxnet/python/mxboard/proto/event_pb2.py in () 14 15 ---> 16 from mxboard.proto import summary_pb2 as mxboard_dot_proto_dot_summary__pb2 17 18

    /home/users/nn/code/py/mxnet/python/mxboard/proto/summary_pb2.py in () 14 15 ---> 16 from mxboard.proto import tensor_pb2 as mxboard_dot_proto_dot_tensor__pb2 17 18

    /home/users/nn/code/py/mxnet/python/mxboard/proto/tensor_pb2.py in () 14 15 ---> 16 from mxboard.proto import resource_handle_pb2 as mxboard_dot_proto_dot_resource__handle__pb2 17 from mxboard.proto import tensor_shape_pb2 as mxboard_dot_proto_dot_tensor__shape__pb2 18 from mxboard.proto import types_pb2 as mxboard_dot_proto_dot_types__pb2

    /home/users/nn/code/py/mxnet/python/mxboard/proto/resource_handle_pb2.py in () 39 message_type=None, enum_type=None, containing_type=None, 40 is_extension=False, extension_scope=None, ---> 41 options=None, file=DESCRIPTOR), 42 _descriptor.FieldDescriptor( 43 name='container', full_name='tensorboard.ResourceHandleProto.container', index=1,

    TypeError: new() got an unexpected keyword argument 'file'`

    opened by firestonelib 5
  • Configuring logging output

    Configuring logging output

    Is it possible to configure the logger of mxboard? If one uses frequent statements as such

    with SummarWriter(logdir=.) as sw:
      sw.add_scalar()
    

    the log of the application becomes quite cluttered with outputs like:

    [INFO:root] Successfully opened events file: events.out.tfevents.1522834055.186590d665ad.ant.amazon.com
    [INFO:root] Wrote 1 event to disk
    [INFO:root] Wrote 1 event to disk
    [INFO:root] Wrote 6 events to disk
    
    question 
    opened by fhieber 5
  • How to record histrogram of nueron network when one of its layer is set to use pre-trained weights?

    How to record histrogram of nueron network when one of its layer is set to use pre-trained weights?

    I followed this gluon's document classification tutorial and tried to visualise my training with mxboard. So far I can visualise my model architecture, training loss, and accuracy.

    However, my problem is when I want to record histograms of my model. Python throws this error:

    Runtime Error: "Cannot get gradient array for Parameter [my layer name] because grad_req='null'"

    then I checked my model initialise block and found these lines:

    model.embedding_layer.weight.set_data(vocab.embedding.idx_to_vec)
    model.embedding_layer.collect_params().setattr('grad_req', 'null')
    

    and mxnet didn't run the gradient for this layer because I want to use my pre-trained embedding.

    So, my question is how do I get gradients for the other layers except for the embedding layer?

    opened by bkktimber 3
  • add support for multi labels for embeddings

    add support for multi labels for embeddings

    This pr adds support for multi labels per data point for the tensorboard embeddings. This means you can now pass a either a 1D or 2D list/numpy.ndarray/mx.ndarray for the labels to the add_embedding for use in tensorboard. The file format for the 2D label input is a TSV with column headers based on the tensorboard documentation https://www.tensorflow.org/guide/embedding#metadata

    I tired to cover my bases with the input checking, any suggestions for improvements are appreciated.

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    opened by jessebrizzi 3
  • import error

    import error

    root@gpu05:/opt/package# pip install mxboard
    Requirement already satisfied: mxboard in /usr/local/anaconda2/lib/python2.7/site-packages (0.1.0)
    Requirement already satisfied: six in /usr/local/anaconda2/lib/python2.7/site-packages (from mxboard) (1.11.0)
    Requirement already satisfied: numpy in /usr/local/anaconda2/lib/python2.7/site-packages (from mxboard) (1.13.3)
    Requirement already satisfied: Pillow in /usr/local/anaconda2/lib/python2.7/site-packages (from mxboard) (4.2.1)
    Requirement already satisfied: protobuf>=3.0.0 in /usr/local/anaconda2/lib/python2.7/site-packages (from mxboard) (3.5.2)
    Requirement already satisfied: olefile in /usr/local/anaconda2/lib/python2.7/site-packages (from Pillow->mxboard) (0.44)
    Requirement already satisfied: setuptools in /usr/local/anaconda2/lib/python2.7/site-packages (from protobuf>=3.0.0->mxboard) (36.5.0.post20170921)
    root@gpu05:/opt/package# python mxboard.py
    Traceback (most recent call last):
      File "mxboard.py", line 2, in <module>
        from mxboard import SummaryWriter
      File "/opt/package/mxboard.py", line 2, in <module>
        from mxboard import SummaryWriter
    ImportError: cannot import name SummaryWriter
    root@gpu05:/opt/package#
    
    This problem has been bothering me for a long time
    
    if I only import mxboard, it does not have error. when I run the mxboard demo, it report this error.
    
    opened by as754770178 3
  • Change README: tensorboard no longer requires tensorflow

    Change README: tensorboard no longer requires tensorflow

    Issue #, if available:

    Description of changes: Tensorboard no longer requires TensorFlow, so remove tensorflow from the installation instruction for tensorboard.

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    @reminisce

    opened by hcho3 2
  • Revert

    Revert "fix text_summary for newer version of tensorboard (#32)"

    This reverts commit 2be9b6ef174ec35165321e70636e0f73232bf384.

    Issue #, if available:

    Description of changes:

    By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

    opened by SamanthaFeidFischer 2
  • A tiny bug in making sprite image for embedding projector

    A tiny bug in making sprite image for embedding projector

    Hi,

    I just found a ting bug in how the current mxboard generating the sprite image for embedding projector. This bug may result in wrong embedding-thumbnail association. A simple example borrowed from here is shown as below.

    import numpy as np
    import mxnet as mx
    from mxnet import gluon
    from mxboard import SummaryWriter
    
    
    batch_size = 65
    
    
    def transformer(data, label):
        data = data.reshape((-1,)).astype(np.float32)/255
        return data, label
    
    train_data = gluon.data.DataLoader(
        gluon.data.vision.MNIST('./data', train=True, transform=transformer),
        batch_size=batch_size, shuffle=False, last_batch='discard')
    
    initialized = False
    embedding = None
    labels = None
    images = None
    
    for i, (data, label) in enumerate(train_data):
        if i >= 1:
            # only fetch the first batche of images, i.e. 65 images -> 8*9 sprite image
            break
        if initialized:
            embedding = mx.nd.concat(*(embedding, data), dim=0)
            labels = mx.nd.concat(*(labels, label), dim=0)
            images = mx.nd.concat(*(images, data.reshape(batch_size, 1, 28, 28)), dim=0)
        else:
            embedding = data
            labels = label
            images = data.reshape(batch_size, 1, 28, 28)
            initialized = True
    
    with SummaryWriter(logdir='./logs') as sw:
        sw.add_embedding(tag='mnist', embedding=embedding, labels=labels, images=images)
    

    The above code takes 65 images of handwritten digits from the MNIST dataset and log them as embedding vectors with labels and original images. The generated sprite image is of grid 8 * 9, which is not square:

    sprite

    But, the current TensorBoard requires a square sprite image for the embedding projector working correctly (see here). So, the above non-square sprite image will make the thumbnails misaligned with their embeddings:

    screenshot 2019-01-14 at 18 10 49

    (e.g. embedding at the center of label 2 is displayed with thumbnail '9')

    This issue can be easily solved by changing just one line to constrain the produced sprite image to be precisely squared:

    sprite

    I tested it locally and would like to make a pull request. ;)

    opened by YusongLeng 2
  • Support summary written to HDFS

    Support summary written to HDFS

    This PR supports use case below:

    from mxboard import SummaryWriter
    with SummaryWriter(logdir='hdfs://hdfs-nn-proxy-ns1/department/ai/user/xyz/logs') as sw:
        for i in range(10):
            # create a normal distribution with fixed mean and decreasing std
            data = mx.nd.normal(loc=0, scale=10.0/(i+1), shape=(10, 3, 8, 8))
            sw.add_histogram(tag='norml_dist', values=data, bins=200, global_step=i)
    
    opened by 372046933 0
  • Proto file duplication issue.

    Proto file duplication issue.

    TypeError: Conflict register for file "mxboard/proto/resource_handle.proto": tensorboard.ResourceHandleProto is already defined in file "tensorboard/compat/proto/resource_handle.proto". Please fix the conflict by adding package name on the proto file, or use different name for the duplication. ... File "C:\Users\selcu\anaconda3\lib\site-packages\mxboard_init_.py", line 21, in from .writer import SummaryWriter File "C:\Users\selcu\anaconda3\lib\site-packages\mxboard\writer.py", line 28, in from .proto import event_pb2 File "C:\Users\selcu\anaconda3\lib\site-packages\mxboard\proto\event_pb2.py", line 16, in from mxboard.proto import summary_pb2 as mxboard_dot_proto_dot_summary__pb2 File "C:\Users\selcu\anaconda3\lib\site-packages\mxboard\proto\summary_pb2.py", line 16, in from mxboard.proto import tensor_pb2 as mxboard_dot_proto_dot_tensor__pb2 File "C:\Users\selcu\anaconda3\lib\site-packages\mxboard\proto\tensor_pb2.py", line 16, in from mxboard.proto import resource_handle_pb2 as mxboard_dot_proto_dot_resource__handle__pb2 File "C:\Users\selcu\anaconda3\lib\site-packages\mxboard\proto\resource_handle_pb2.py", line 94, in _sym_db.RegisterMessage(ResourceHandleProto) File "C:\Users\selcu\anaconda3\lib\site-packages\google\protobuf\symbol_database.py", line 84, in RegisterMessage self.RegisterMessageDescriptor(desc) File "C:\Users\selcu\anaconda3\lib\site-packages\google\protobuf\symbol_database.py", line 95, in RegisterMessageDescriptor self.pool._AddDescriptor(message_descriptor) File "C:\Users\selcu\anaconda3\lib\site-packages\google\protobuf\descriptor_pool.py", line 238, in _AddDescriptor self._CheckConflictRegister(desc, desc.full_name, desc.file.name) File "C:\Users\selcu\anaconda3\lib\site-packages\google\protobuf\descriptor_pool.py", line 191, in _CheckConflictRegister raise TypeError(error_msg) TypeError: Conflict register for file "mxboard/proto/resource_handle.proto": tensorboard.ResourceHandleProto is already defined in file "tensorboard/compat/proto/resource_handle.proto". Please fix the conflict by adding package name on the proto file, or use different name for the duplication.

    Process finished with exit code 1

    opened by develooper1994 2
  • Networks with BatchNorm and gradients

    Networks with BatchNorm and gradients

    I have set the i.grad != "null" which I found in here but now I receive error conv0_weight' was not initialized on context cpu(0). It was only initialized on [gpu(0), gpu(1)], but if I run it on just one gpu I receive the assertion error len(grads) == len(param_names) this occurs on all nets with a BatchNorm ones I have written and one in gluon's model zoo tried Inception, Densenet121 error:

    grads = [i.grad() for i in net.collect_params().values() if i.grad_req != 'null'] 50 assert len(grads) == len(param_names) 51

    in (.0) 47 sw.add_graph(net) 48 ---> 49 grads = [i.grad() for i in net.collect_params().values() if i.grad_req != 'null'] 50 assert len(grads) == len(param_names) 51

    /usr/local/lib/python3.6/dist-packages/mxnet/gluon/parameter.py in grad(self, ctx) 570 "Cannot get gradient array for Parameter '%s' "
    571 "because grad_req='null'"%(self.name)) --> 572 return self._check_and_get(self._grad, ctx) 573 574 def list_grad(self):

    /usr/local/lib/python3.6/dist-packages/mxnet/gluon/parameter.py in _check_and_get(self, arr_list, ctx) 225 "Parameter '%s' was not initialized on context %s. " 226 "It was only initialized on %s."%( --> 227 self.name, str(ctx), str(self._ctx_list))) 228 if self._deferred_init: 229 raise DeferredInitializationError(

    RuntimeError: Parameter 'densenet0_conv0_weight' was not initialized on context cpu(0). It was only initialized on [gpu(0), gpu(1)].

    opened by hskramer 0
  •  Appending to event file

    Appending to event file

    Is there a way to make SummaryWriter append to old event file, instead of creating new one each time it's called?

    Or is there any other method to prepare log files, so that if I interrupt and then continue training later, get a desired Tensorboard output (and not just graph with duplicated values)?.

    good first issue question 
    opened by lambdaofgod 1
Releases(v0.1.0)
  • v0.1.0(May 22, 2018)

    MXBoard Change Log

    v0.1.0 (first release)

    Supports logging MXNet data and visualizing them as Graph, Scalar, Histogram, Embedding, Image, Text, PR-Curve, or Audio in TensorBoard.

    Source code(tar.gz)
    Source code(zip)
Owner
Amazon Web Services - Labs
AWS Labs
Amazon Web Services - Labs
🎆 A visualization of the CapsNet layers to better understand how it works

CapsNet-Visualization For more information on capsule networks check out my Medium articles here and here. Setup Use pip to install the required pytho

Nick Bourdakos 387 Dec 6, 2022
Visualization Toolbox for Long Short Term Memory networks (LSTMs)

Visualization Toolbox for Long Short Term Memory networks (LSTMs)

Hendrik Strobelt 1.1k Jan 4, 2023
null 131 Jun 25, 2021
Neural network visualization toolkit for tf.keras

Neural network visualization toolkit for tf.keras

Yasuhiro Kubota 262 Dec 19, 2022
Pytorch implementation of convolutional neural network visualization techniques

Convolutional Neural Network Visualizations This repository contains a number of convolutional neural network visualization techniques implemented in

Utku Ozbulak 7k Jan 3, 2023
Visualization toolkit for neural networks in PyTorch! Demo -->

FlashTorch A Python visualization toolkit, built with PyTorch, for neural networks in PyTorch. Neural networks are often described as "black box". The

Misa Ogura 692 Dec 29, 2022
GNNLens2 is an interactive visualization tool for graph neural networks (GNN).

GNNLens2 is an interactive visualization tool for graph neural networks (GNN).

Distributed (Deep) Machine Learning Community 143 Jan 7, 2023
Convolutional neural network visualization techniques implemented in PyTorch.

This repository contains a number of convolutional neural network visualization techniques implemented in PyTorch.

null 1 Nov 6, 2021
Interactive convnet features visualization for Keras

Quiver Interactive convnet features visualization for Keras The quiver workflow Video Demo Build your model in keras model = Model(...) Launch the vis

Keplr 1.7k Dec 21, 2022
A data-driven approach to quantify the value of classifiers in a machine learning ensemble.

Documentation | External Resources | Research Paper Shapley is a Python library for evaluating binary classifiers in a machine learning ensemble. The

Benedek Rozemberczki 187 Dec 27, 2022
Interpretability and explainability of data and machine learning models

AI Explainability 360 (v0.2.1) The AI Explainability 360 toolkit is an open-source library that supports interpretability and explainability of datase

null 1.2k Dec 29, 2022
tensorboard for pytorch (and chainer, mxnet, numpy, ...)

tensorboardX Write TensorBoard events with simple function call. The current release (v2.1) is tested on anaconda3, with PyTorch 1.5.1 / torchvision 0

Tzu-Wei Huang 7.5k Jan 7, 2023
Tensorboard for pytorch (and chainer, mxnet, numpy, ...)

tensorboardX Write TensorBoard events with simple function call. The current release (v2.3) is tested on anaconda3, with PyTorch 1.8.1 / torchvision 0

Tzu-Wei Huang 7.5k Dec 28, 2022
Streamlit component for TensorBoard, TensorFlow's visualization toolkit

streamlit-tensorboard This is a work-in-progress, providing a function to embed TensorBoard, TensorFlow's visualization toolkit, in Streamlit apps. In

Snehan Kekre 27 Nov 13, 2022
Logging-monitoring-instrumentation - A brief repository on logging monitoring and instrumentation in Python

logging-monitoring-instrumentation A brief repository on logging monitoring and

Noah Gift 6 Feb 17, 2022
MMdnn is a set of tools to help users inter-operate among different deep learning frameworks. E.g. model conversion and visualization. Convert models between Caffe, Keras, MXNet, Tensorflow, CNTK, PyTorch Onnx and CoreML.

MMdnn MMdnn is a comprehensive and cross-framework tool to convert, visualize and diagnose deep learning (DL) models. The "MM" stands for model manage

Microsoft 5.7k Jan 9, 2023
Tensorboard plugin 3d with python

tensorboard-plugin-3d Overview In this example, we render a run selector dropdown component. When the user selects a run, it shows a preview of all sc

KitwareMedical 26 Nov 14, 2022
Visualize the training curve from the *.csv file (tensorboard format).

Training-Curve-Vis Visualize the training curve from the *.csv file (tensorboard format). Feature Custom labels Curve smoothing Support for multiple c

Luckky 7 Feb 23, 2022
Sequence-to-sequence framework with a focus on Neural Machine Translation based on Apache MXNet

Sockeye This package contains the Sockeye project, an open-source sequence-to-sequence framework for Neural Machine Translation based on Apache MXNet

Amazon Web Services - Labs 1.1k Dec 27, 2022
Sequence-to-sequence framework with a focus on Neural Machine Translation based on Apache MXNet

Sockeye This package contains the Sockeye project, an open-source sequence-to-sequence framework for Neural Machine Translation based on Apache MXNet

Amazon Web Services - Labs 986 Feb 17, 2021