Created
October 23, 2018 12:19
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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