TensorBoard介绍

数据写入FDS

生成运算的graph参考TensorBoard使用文档,路径直接使用fds的路径即可。需要注意的是,与直接使用官方tensorboard不同,在SummaryWriter结束的时候,需要进行close操作,否则数据写入不完整,会有部分数据丢失。

  1. #!/usr/bin/env python
  2. import tensorflow as tf
  3. import numpy as np
  4. train_X = np.linspace(-1, 1, 101)
  5. train_Y = 2 * train_X + np.random.randn(*train_X.shape) * 0.33 + 10
  6. X = tf.placeholder("float")
  7. Y = tf.placeholder("float")
  8. w = tf.Variable(0.0, name="weight")
  9. b = tf.Variable(0.0, name="reminder")
  10. init_op = tf.initialize_all_variables()
  11. cost_op = tf.square(Y - tf.mul(X, w) - b)
  12. train_op = tf.train.GradientDescentOptimizer(0.01).minimize(cost_op)
  13. with tf.Session() as sess:
  14. sess.run(init_op)
  15. #直接使用fds路径
  16. writer = tf.train.SummaryWriter("fds://cloudml/test", sess.graph)
  17. for i in range(10):
  18. for (x, y) in zip(train_X, train_Y):
  19. sess.run(train_op, feed_dict={X: x, Y: y})
  20. print(sess.run(w))
  21. print(sess.run(b))
  22. #结尾进行close
  23. writer.close()

读取FDS的文件

需要先安装带fds版本的tensorflow。

fds的路径访问格式为:"fds://%s:%s@%s.%s/test/summary/" % (ID, SECRET, BUCKET, ENDPOINT),如:

  1. tensorboard --inspect --logdir=fds://AK7AUPxxxxQQK2:3tJamiK8zpgkWxxxxxxx7lvIcelQfpn@tensorflow-test.cnbj1-fds.api.xiaomi.net/galaxy-hadoop-test/input.txt

或者使用环境变量。

  1. export XIAOMI_ACCESS_KEY_ID="AKRCxxxxxxxxxxxY7EG"
  2. export XIAOMI_SECRET_ACCESS_KEY="w0TYaxxxxxxxxxxxxxxxxxxxxxxxxxxxtmXAeWbqMw"
  3. tensorboard --logdir fds://cloud-ml-test.cnbj1-fds.api.xiaomi.net/demo3_tensorboard/

原文: http://docs.api.xiaomi.com/cloud-ml/tensorboardservice/tensorboard.html