HyperAIHyperAI

Using TensorBoard

To facilitate better understanding, debugging, and optimization of TensorFlow programs, the TensorFlow team has released a visualization tool suite called TensorBoard. TensorBoard can be used to display TensorFlow graphs, plot quantitative metric charts generated during training, and show additional data (such as images passed through the network).

Currently, HyperAI containers support TensorBoard when creating Tasks or Jupyter workspaces.

The following code example demonstrates how to specify TensorBoard usage during training:

def create_model():
  model = tf.keras.models.Sequential([
  tf.keras.layers.Dense(512, activation=tf.nn.relu, input_shape=(img_rows * img_cols,)),
  tf.keras.layers.Dropout(0.2),
  tf.keras.layers.Dense(num_classes, activation=tf.nn.softmax)
])

  model.compile(optimizer='adam',
              loss='sparse_categorical_crossentropy',
              metrics=['accuracy'])

  return model

model = create_model()
model.summary()

log_path = './tf_dir'

# Set TensorBoard path to tf_dir
tb_callback = tf.keras.callbacks.TensorBoard(log_dir=log_path)

model.fit(x_train, y_train,
          epochs=epochs,
          verbose=1,
          callbacks=[tb_callback])

For the complete code, see MNist Example.

:::caution Note As shown in the figure below, we specify by default that the TensorBoard data retrieval directory is the tf_dir folder under /openbayes/home. Therefore, if you need to display TensorBoard data, please make sure to set the log_dir of TensorBoard to this directory. :::

For successfully running containers, an "Open TensorBoard" button will appear on the page. Click it to view the running TensorBoard.

TensorBoard can only be viewed when the container is in running state. If you want to view TensorBoard after the container has stopped, please download the "working directory" to your local machine and view its contents by installing TensorBoard locally:

tensorboard --logdir=<TensorBoard data directory>

Then open http://localhost:6006/ in your browser.