{"action":"created","issue":{"url":"https://api.github.com/repos/dmlc/mxnet/issues/4003","repository_url":"https://api.github.com/repos/dmlc/mxnet","labels_url":"https://api.github.com/repos/dmlc/mxnet/issues/4003/labels{/name}","comments_url":"https://api.github.com/repos/dmlc/mxnet/issues/4003/comments","events_url":"https://api.github.com/repos/dmlc/mxnet/issues/4003/events","html_url":"https://github.com/dmlc/mxnet/issues/4003","id":191874054,"number":4003,"title":"Building a visualization tool for MXNet","user":{"login":"zihaolucky","id":4514568,"avatar_url":"https://avatars.githubusercontent.com/u/4514568?v=3","gravatar_id":"","url":"https://api.github.com/users/zihaolucky","html_url":"https://github.com/zihaolucky","followers_url":"https://api.github.com/users/zihaolucky/followers","following_url":"https://api.github.com/users/zihaolucky/following{/other_user}","gists_url":"https://api.github.com/users/zihaolucky/gists{/gist_id}","starred_url":"https://api.github.com/users/zihaolucky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zihaolucky/subscriptions","organizations_url":"https://api.github.com/users/zihaolucky/orgs","repos_url":"https://api.github.com/users/zihaolucky/repos","events_url":"https://api.github.com/users/zihaolucky/events{/privacy}","received_events_url":"https://api.github.com/users/zihaolucky/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":21,"created_at":"2016-11-27T17:41:31Z","updated_at":"2016-12-11T18:45:45Z","closed_at":null,"body":"Hi hackers,\r\n\r\nI've started working on building a visualization tool for MXNet, like TensorBoard for TensorFlow. As @piiswrong suggested in #3306 that '*try to strip TensorBoard out of tensorflow*' and I'm going to work on this direction. Here're some of my notes after reading TensorBoard‘s documentation and searching its usage on the web, feel free to comment below.\r\n\r\n## Motivation and some backgrounds\r\n\r\nI've tried to visualize the data using `matplotlib` and a bunch of helper tools like `tsne` on my daily work and I feel tired in rendering and adjusting the size/color of the images. Besides, it's not easy to share this data with my friends.\r\n\r\nWhile TensorBoard provides good solutions for our daily use cases, such as learning curves, parameters/embedding visualization, also it's easy to share. See [TensorBoard](https://www.tensorflow.org/versions/master/how_tos/summaries_and_tensorboard/index.html) for more. \r\n\r\n### Daily use cases \r\n\r\n * Learning Curves. Visualize a scalar metric in training/testing such as accuracy, loss or some custom evaluation metrics.\r\n * Parameters insights. Like CNN's filters. Or parameters' histogram over time to debug gradient vanish by checking.\r\n * Embedding visualization. Some applications will visualize high dimension embedding data in a layer, like the last FullyConnect layer's output. In this case, tSNE is commonly used.\r\n\r\nI think these could satisfy most people and it's already supported by TensorBoard with `tf.scalar_summary`, `tf.image_summary`, `tf.histogram_summary` and [tensorboard.plugins.projector](https://www.tensorflow.org/versions/master/how_tos/embedding_viz/index.html#tensorboard-embedding-visualization)\r\n\r\n### TensorBoard usage\r\n\r\nSome snippets from a [tutorial](https://ischlag.github.io/2016/06/04/how-to-use-tensorboard/) on how to use TensorBoard.\r\n\r\n```python\r\n# create a summary for our cost and accuracy\r\ntf.scalar_summary(\"cost\", cross_entropy)\r\ntf.scalar_summary(\"accuracy\", accuracy)\r\n\r\n# merge all summaries into a single \"operation\" which we can execute in a session \r\nsummary_op = tf.merge_all_summaries()\r\n\r\nwith tf.Session() as sess:\r\n    # variables need to be initialized before we can use them\r\n    sess.run(tf.initialize_all_variables())\r\n\r\n    # create log writer object\r\n    writer = tf.train.SummaryWriter(logs_path, graph=tf.get_default_graph())\r\n        \r\n    # perform training cycles\r\n    for epoch in range(training_epochs):\r\n        \r\n        # number of batches in one epoch\r\n        batch_count = int(mnist.train.num_examples/batch_size)\r\n        \r\n        for i in range(batch_count):\r\n            batch_x, batch_y = mnist.train.next_batch(batch_size)\r\n            \r\n            # perform the operations we defined earlier on batch\r\n            _, summary = sess.run([train_op, summary_op], feed_dict={x: batch_x, y_: batch_y})\r\n            \r\n            # write log\r\n            writer.add_summary(summary, epoch * batch_count + i)\r\n```\r\n\r\nThe logic above is quite clear, where the `accuracy` and `cost ` get updated every time when `sess.run` is called and return a [Summary]() which is feed into log through `SummaryWriter`.\r\n\r\n## Feasibility \r\n\r\n### 1.Easy to borrow and directly use in MXNet? \r\n\r\nI've successfully visualized the 'makeup' curve using the code below:\r\n\r\n```python\r\ncounter = tf.Variable(1.0)\r\n\r\n# create a summary for counter\r\ntf.scalar_summary(\"counter\", counter)\r\n\r\n# merge all summaries into a single \"operation\" which we can execute in a session\r\nsummary_op = tf.merge_all_summaries()\r\n\r\nwith tf.Session() as sess:\r\n    # variables need to be initialized before we can use them\r\n    sess.run(tf.initialize_all_variables())\r\n\r\n    # create log writer object\r\n    writer = tf.train.SummaryWriter(logs_path, graph=tf.get_default_graph())\r\n\r\n    # perform training cycles\r\n    for epoch in range(100):\r\n\r\n        # perform the operations we defined earlier on batch\r\n        counter.assign(epoch + np.random.standard_normal()).eval()\r\n        summary = sess.run(summary_op)\r\n\r\n        # write log\r\n        writer.add_summary(summary, epoch)\r\n```\r\n\r\nSo it means we could pass something common, here is numpy array and normal int, and reuse most of the code. *I would discuss possible routes for creating an interface to connect MXNet and TensorBoard and I need your advice. But let's keep it simple now.*\r\n\r\n### 2.Could be striped alone?\r\n\r\nFrom this [README](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tensorboard/README.md), I guess TensorBoard could be built independently?\r\n\r\n> Or, if you are building from source:\r\n\r\n```\r\nbazel build tensorflow/tensorboard:tensorboard\r\n./bazel-bin/tensorflow/tensorboard/tensorboard --logdir=path/to/logs\r\n```\r\n\r\n\r\n## TODO\r\n\r\nTo prove we can use TensorBoard in a dummy way:\r\n- [x] Run several MXNet examples with minimum code from TF and visualize the outputs. \r\n\r\nTo keep our code clean and lightweight:\r\n- [ ] Varify whether TensorBoard could be built independently. \r\n\r\nOr we could install entire TF together with MXNet? Is that acceptable? \r\nI think it's okay but not good for our users and make this visualization tool too heavy, cause we also run core code in TensorFlow(the `sess` and `Tensor.eval` is actually computed by TF). But it depends on our checks, hard to tell. \r\n\r\nOr any other way to workaround? As the `summary` is a proto in `writer.add_summary(summary, epoch * batch_count + i)` that means we could only use `summaryWriter` without using the computation of TF. It's possible because the doc in `SummaryWriter.add_summary`:\r\n\r\n```python\r\n  def add_summary(self, summary, global_step=None):\r\n    \"\"\"Adds a `Summary` protocol buffer to the event file.\r\n\r\n    This method wraps the provided summary in an `Event` protocol buffer\r\n    and adds it to the event file.\r\n\r\n    You can pass the result of evaluating any summary op, using\r\n    [`Session.run()`](client.md#Session.run) or\r\n    [`Tensor.eval()`](framework.md#Tensor.eval), to this\r\n    function. Alternatively, you can pass a `tf.Summary` protocol\r\n    buffer that you populate with your own data. The latter is\r\n    commonly done to report evaluation results in event files.\r\n\r\n    Args:\r\n      summary: A `Summary` protocol buffer, optionally serialized as a string.\r\n      global_step: Number. Optional global step value to record with the\r\n        summary.\r\n    \"\"\"\r\n```\r\n\r\nIf we decide to borrow TensorBoard:\r\n- [ ] Decide where to put the interface and what to do next, based on our experiments above."},"comment":{"url":"https://api.github.com/repos/dmlc/mxnet/issues/comments/266299280","html_url":"https://github.com/dmlc/mxnet/issues/4003#issuecomment-266299280","issue_url":"https://api.github.com/repos/dmlc/mxnet/issues/4003","id":266299280,"user":{"login":"tqchen","id":2577440,"avatar_url":"https://avatars.githubusercontent.com/u/2577440?v=3","gravatar_id":"","url":"https://api.github.com/users/tqchen","html_url":"https://github.com/tqchen","followers_url":"https://api.github.com/users/tqchen/followers","following_url":"https://api.github.com/users/tqchen/following{/other_user}","gists_url":"https://api.github.com/users/tqchen/gists{/gist_id}","starred_url":"https://api.github.com/users/tqchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tqchen/subscriptions","organizations_url":"https://api.github.com/users/tqchen/orgs","repos_url":"https://api.github.com/users/tqchen/repos","events_url":"https://api.github.com/users/tqchen/events{/privacy}","received_events_url":"https://api.github.com/users/tqchen/received_events","type":"User","site_admin":false},"created_at":"2016-12-11T18:45:45Z","updated_at":"2016-12-11T18:45:45Z","body":"It would be necessary to copy the LICENSE file from original repo, and retaining the copy right notice"}}
{"actor":{"display_login":"tqchen"}}