/mxboard

Logging MXNet data for visualization in TensorBoard.

Primary LanguagePythonApache License 2.0Apache-2.0

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 tensorflow 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.