In [0]:
#@title Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Getting started with TensorBoard.dev

TensorBoard.dev provides a managed TensorBoard experience that lets you upload and share your ML experiment results with everyone.

This notebook trains a simple model and shows how to upload the logs to TensorBoard.dev.

Setup and imports


In [0]:
%tensorflow_version 2.x
!pip install -U tensorboard >piplog 2>&1

In [0]:
import tensorflow as tf
import datetime

Train a simple model and create TensorBoard logs


In [0]:
mnist = tf.keras.datasets.mnist

(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0

def create_model():
  return tf.keras.models.Sequential([
    tf.keras.layers.Flatten(input_shape=(28, 28)),
    tf.keras.layers.Dense(512, activation='relu'),
    tf.keras.layers.Dropout(0.2),
    tf.keras.layers.Dense(10, activation='softmax')
  ])

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

log_dir="logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)

model.fit(x=x_train, 
          y=y_train, 
          epochs=5, 
          validation_data=(x_test, y_test), 
          callbacks=[tensorboard_callback])

Upload to TensorBoard.dev

Uploading the TensorBoard logs will give a link that can be shared with anyone. Note that uploaded TensorBoards are public. Do not upload sensitive data.

The uploader will keep running until it is stopped, in order to read new data from the directory during ongoing training.


In [0]:
!tensorboard dev upload --logdir ./logs