LoginSignup
7
13

More than 5 years have passed since last update.

TensorBoardの最もシンプルなサンプル

Last updated at Posted at 2017-12-03

追記

もう少し実用的な記事を書いた
TensorBoardのシンプルな解説

環境

$ python3 --version
Python 3.5.4
$ pip3 list|grep tensor
tensorboard (1.0.0a6)
tensorflow (1.4.0)
tensorflow-tensorboard (0.4.0rc3)

インストール

$ pip3 install tensorflow tensorboard

サンプル

c = a + b のグラフをTensorBoardで表示

tensorboard_graph.py
import tensorflow as tf

a = tf.constant(2, name='A')
b = tf.constant(3, name='B')
c = tf.add(a, b, name='C')

sess = tf.InteractiveSession()
writer = tf.summary.FileWriter('./logdir', sess.graph)
tf.global_variables_initializer().run()
print(sess.run(c))
$ python3 tensorboard_graph.py
5
$ tensorboard --logdir='./logdir'
TensorBoard 0.4.0rc3 at http://localhost:6006 (Press CTRL+C to quit)

するとカレントディレクトリにlogdirが生成され,その中にグラフの情報が保存れる.
ブラウザで http://localhost:6006 にアクセスするとTensorBoardの画面が表示される.
tensorboard_graph.png

TensorBoardは表示されるがグラフが表示されない場合

$ python3 tensorboard_graph.py
の前に
$ rm -rf ./logdir
を実行する.
その時tensorboardは終了しておく.

7
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
13