1.9.2 TensorBoard介绍

优质
小牛编辑
131浏览
2023-12-01

数据写入FDS

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

#!/usr/bin/env python

import tensorflow as tf
import numpy as np

train_X = np.linspace(-1, 1, 101)
train_Y = 2 * train_X + np.random.randn(*train_X.shape) * 0.33 + 10

X = tf.placeholder("float")
Y = tf.placeholder("float")
w = tf.Variable(0.0, name="weight")
b = tf.Variable(0.0, name="reminder")

init_op = tf.initialize_all_variables()
cost_op = tf.square(Y - tf.mul(X, w) - b)
train_op = tf.train.GradientDescentOptimizer(0.01).minimize(cost_op)

with tf.Session() as sess:
  sess.run(init_op)

  #直接使用fds路径
  writer = tf.train.SummaryWriter("fds://cloudml/test", sess.graph)

  for i in range(10):
    for (x, y) in zip(train_X, train_Y):
      sess.run(train_op, feed_dict={X: x, Y: y})

  print(sess.run(w))
  print(sess.run(b))
  #结尾进行close
  writer.close()

读取FDS的文件

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

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

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

或者使用环境变量。

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