Skip to content

Instantly share code, notes, and snippets.

@xmodar
Created October 23, 2018 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xmodar/cf8c009c0cc03ab340a8e07cfa696023 to your computer and use it in GitHub Desktop.
Save xmodar/cf8c009c0cc03ab340a8e07cfa696023 to your computer and use it in GitHub Desktop.
If you want to dump histograms in tensorboard while using pytorch, following [this tutorial](https://nbviewer.jupyter.org/gist/ModarTensai/b081dcf6c87f9134f29abe3a77be1ab5), you can use this.
import torch
import tensorflow as tf
def histogram_summary(name, array):
if not hasattr(histogram_summary, 'session'):
histogram_summary.placeholder = tf.placeholder(tf.float32)
histogram_summary.session = tf.Session()
histogram_summary.histograms = {}
if name not in histogram_summary.histograms:
histogram_summary.histograms[name] = tf.summary.histogram(
name, histogram_summary.placeholder)
histogram = histogram_summary.session.run(
histogram_summary.histograms[name],
feed_dict={histogram_summary.placeholder: array}
)
return histogram
writer = tf.summary.FileWriter("exps/histogram_example")
writer.add_summary(histogram_summary('model_1/loss', torch.randn(100).numpy()))
writer.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment