teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

データ作成~表示までのサンプル追加

2017/03/15 01:19

投稿

8524ba23
8524ba23

スコア38352

answer CHANGED
@@ -18,4 +18,62 @@
18
18
  Starting TensorBoard b'41' on port 6006
19
19
  (You can navigate to http://172.xx.xx.xx:6006)
20
20
  :(以下略)
21
- ```
21
+ ```
22
+
23
+ 2017/03/15追記 : データ作成~表示までの実行例
24
+ --
25
+
26
+ - 可視化したいデータ作成
27
+ 参考:[TensorBoardで処理を可視化する](http://www.mwsoft.jp/programming/tensor/tutorial_tensorboad.html)
28
+ ```Python
29
+ # -*- coding: utf-8 -*-
30
+ import tensorflow as tf
31
+
32
+ # 足し算
33
+ with tf.name_scope('add_scope'):
34
+ x = tf.constant(1, name='x')
35
+ y = tf.constant(2, name='y')
36
+ z = x + y
37
+
38
+ # 上の結果に掛け算
39
+ with tf.name_scope('multiply_scope'):
40
+ zz = y * z
41
+
42
+ with tf.Session() as sess:
43
+ with tf.name_scope('init_scope'):
44
+ # WARNING:tensorflow:From hoge.py initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
45
+ # Instructions for updating:
46
+ # Use `tf.global_variables_initializer` instead.
47
+ #sess.run(tf.initialize_all_variables())
48
+ sess.run(tf.global_variables_initializer())
49
+ sess.run(zz)
50
+
51
+ # グラフを書こう
52
+ # AttributeError: module 'tensorflow.python.training.training' has no attribute 'SummaryWriter' #8164
53
+ # https://github.com/tensorflow/tensorflow/issues/8164
54
+ #summary_writer = tf.train.SummaryWriter('data', graph=sess.graph)
55
+ summary_writer = tf.summary.FileWriter('c:\\temp\\tf_log', graph=sess.graph)
56
+
57
+ # http://stackoverflow.com/questions/41066244/tensorflow-module-object-has-no-attribute-scalar-summary
58
+ #tf.scalar_summary('one_plus_one_summary', zz)
59
+ tf.summary.scalar('one_plus_one_summary', zz)
60
+
61
+ print("done.")
62
+ ```
63
+ `c:\temp\tf_log`配下にデータ`events.out.tfevents.1489539251.hoge-PC`が作成される。
64
+
65
+ - tensorboard起動
66
+ コマンドプロンプト(cmd.exe)上で以下を実行。
67
+ ```lang=DOS
68
+ C:\Windows\system32>activate tf3
69
+ (tf3) C:\Windows\system32>tensorboard --logdir=c:/temp/tf_log
70
+ Starting TensorBoard b'41' on port 6006
71
+ (You can navigate to http://172.xx.xx.xx:6006)
72
+ ERROR:tensorflow:Unable to get size of ~
73
+ など複数行のエラー、警告が表示されるがとりあえず無視
74
+ WARNING:tensorflow:Found more than one metagraph event per run. Overwriting the
75
+ metagraph with the newest event.
76
+ ```
77
+
78
+ - ブラウザ(chrome)で`http://localhost:6006`を開く
79
+ ![tensorboard](b882648cd39108a0e7f7860889507341.png)