tensorflow / tensorboard

TensorFlow's Visualization Toolkit
Apache License 2.0
6.71k stars 1.66k forks source link

TensorBoard Jupyter Magic HTML Export #2045

Open Queuecumber opened 5 years ago

Queuecumber commented 5 years ago

Tensorflow from tf-nightly-2.0-preview

I frequently using jupyter-nbconvert to share my notebooks as HTML since it's easier to host on a static site and be viewable by anyone. I have recently been using the tensorboard magic to get nice graphs of my metrics and loss as I train, but I found that when I export, these graphs are missing.

It would be nice to be able to export the tensorboard interface somehow. When I do the export, graphs and images from matplotlib are always fine so there should be a way to do it, although it might be up to the nbconvert people.

nfelt commented 5 years ago

Thanks for the feature request - yes, this is a known limitation of the way that the tensorboard magic is currently implemented, since the frontend HTML visualization expects to find an actual running tensorboard backend from which it can fetch data. Unfortunately I suspect it would not be easy to work around this unless there's possibly some way that nbconvert can cache those responses and bundle them with the exported HTML.

cc @wchargin

Queuecumber commented 5 years ago

Interestingly, google colab has no problem displaying the data even when its not connected to a backend, not sure if thats a known thing but however that works would probably be enough

wchargin commented 5 years ago

Colab caches network requests made within a cell output frame and saves them in the notebook directly. If you create a simple Colab notebook with a %tensorboard invocation, then download the ipynb, you can see the cached data:

$ jq '.cells[1].metadata.colab.resources | keys' Downloads/colab_tensorboard_sample.ipynb
[
  "http://localhost:6006/",
  "http://localhost:6006/data/environment",
  "http://localhost:6006/data/experiments",
  "http://localhost:6006/data/plugins_listing",
  "http://localhost:6006/data/runs",
  "http://localhost:6006/font-roboto/RxZJdnzeo3R5zSexge8UUZBw1xU1rKptJj_0jans920.woff2",
  "http://localhost:6006/font-roboto/d-6IYplOFocCacKzxwXSOJBw1xU1rKptJj_0jans920.woff2",
  "http://localhost:6006/font-roboto/vPcynSL0qHq_6dX7lKVByXYhjbSpvc47ee6xR_80Hnw.woff2",
  "http://localhost:6006/tf-interactive-inference-dashboard/distance.png",
  "http://localhost:6006/tf-interactive-inference-dashboard/editedexample.png",
  "http://localhost:6006/tf-interactive-inference-dashboard/explorecounterfactuals.png",
  "http://localhost:6006/tf-interactive-inference-dashboard/pdplots.png"
]
$ jq -r '.cells[1].metadata.colab.resources["http://localhost:6006/data/environment"].data' Downloads/colab_tensorboard_sample.ipynb | base64 -d; echo
{"window_title": "", "mode": "logdir", "data_location": "/tmp/whatever"}

This is the kind of caching mechanism that @nfelt was referring to; nbconvert would need to do something similar, and the generated HTML would need some kind of runtime to actually hook up the cache to the output frame.

Queuecumber commented 5 years ago

Or the caching could be done by the client right?

arif-ahmed-nv commented 9 months ago

Hello, is there any update on this? I have a similar use case where I want to export the static Tensorboard HTML so that I can host it on my own web app and the user doesn't have to deal with launching a Tensorboard instance.

orioninthesky98 commented 3 months ago

Hello, is there any update on this? I have a similar use case where I want to export the static Tensorboard HTML so that I can host it on my own web app and the user doesn't have to deal with launching a Tensorboard instance.

did you find a solution?

orioninthesky98 commented 3 months ago

for what it's worth, images (PNGs, JPEGs) can be easily embedded in HTMLs by converting them to base64 and inserting them into the HTML

arif-ahmed-nv commented 3 months ago

@orioninthesky98 We couldn't figure out a way to get around this issue without launching a dedicated instance for Tensorboard. We would appreciate if a Flask API (or something similar) layer would be added on top of Tensorboard, so that we could simply make GET requests to the Tensorboard instance to receive the content, instead of having the user directly connect to the running instance to view Tensorboard.

wchargin commented 3 months ago

We would appreciate if a Flask API (or something similar) layer would be added on top of Tensorboard, so that we could simply make GET requests to the Tensorboard instance to receive the content

While there isn't an official Flask interface, you can use this trick with the server_class argument to tensorboard.program.TensorBoard to smuggle one out: https://github.com/tensorflow/tensorboard/issues/3709#issuecomment-639687689