Skip to content

Latest commit

 

History

History
128 lines (109 loc) · 5.1 KB

README.md

File metadata and controls

128 lines (109 loc) · 5.1 KB

Logging MXNet Data for Visualization in TensorBoard

Overview

MXBoard provides a set of APIs logging MXNet data for visualization in TensorBoard. The idea of this project comes from the discussion with Zihao Zheng, the author of dmlc/tensorboard, on delivering a visualization solution for MXNet users. We aim at providing the logging APIs that could process MXNet data efficiently and supporting most of the data types for visualization in the TensorBoard GUI. We adapted the low-level logging components, FileWriter, EventFileWriter, EventsWriter, RecordWriter, and _EventLoggerThread, from their Python and C++ implementations in TensorFlow, and 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 currently only supports a set of Python APIs for logging the following data types listed in the TensorBoard GUI. Logging APIs for languages may be added in the future.

The corresponding Python APIs are accessible through a class called SummaryWriter as below.

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

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

Type

tensorboard --help

to verify that the TensorBoard binary has been installed correctly.

Other required packages

MXBoard relies on the following packages for data logging.

Visualizing MXNet data in 30 seconds

After installing all the required packages, let's walk through a simple example demonstrating how MXBoard enables visualizing MXNet NDArrays in terms of histograms in TensorBoard.

  1. 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 becomes more centered around the mean value. Note that here we specify the creating the event file in the folder logs under the current directory. We will need to pass the 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)
  1. Run TensorBoard by typing the following command under the same directory as logs.
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.

  1. 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 evolves. png

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.