Reputation: 3657
I am trying to display a Tensorboard in Google Colab. I import tensorboard: %load_ext tensorboard
, then create a log_dir
, and fit it as follows:
log_dir = '/gdrive/My Drive/project/' + "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)
history = model.fit_generator(
train_generator,
steps_per_epoch=nb_train_samples // batch_size,
epochs=epochs,
validation_data=validation_generator,
validation_steps=nb_validation_samples // batch_size,
callbacks=[tensorboard_callback])
But when I call it with %tensorboard --logdir logs/fit
it doesn't display. Instead, it throws the following message:
No dashboards are active for the current data set.
Is there a solution for this? is the problem in the fixed path I passed in log_dir
?
Upvotes: 3
Views: 5316
Reputation: 639
Maybe you've in some way messed up with the path. If you are working with tensorflow version 2.0+, then please try with this solution
## setup
# Load the TensorBoard notebook extension.
%load_ext tensorboard
Import necessary packages
from datetime import datetime
from packaging import version
import tensorflow as tf
from tensorflow import keras
import numpy as np
print("TensorFlow version: ", tf.__version__)
assert version.parse(tf.__version__).release[0] >= 2, \
"This notebook requires TensorFlow 2.0 or above."
You need to provide tensorboard_callbacks in the callbacks argument in your model.fit() It will appear something like this --
# define path to save log files
logdir = "logs/fit/" + datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = keras.callbacks.TensorBoard(log_dir=logdir, histogram_frequency=1, write_graph=True)
# define & compile your model; here i am moving forward with assumption that you've already defined and compiled your model
model = keras.models.Sequential([
keras.layers.Dense(16, input_dim=1),
keras.layers.Dense(1),
])
model.compile(
loss='mse', # keras.losses.mean_squared_error
optimizer=keras.optimizers.SGD(lr=0.2),
)
# watch closely the argument passed in 'callbacks'
model.fit(x=x_train,
y=y_train,
epochs=10,
validation_data=(x_test, y_test),
callbacks=[tensorboard_callback]))
This will save your log files in the memory allocated in your google colab notebook.
To see the TensorBoard results --
%tensorboard --logdir logs/fit/
Result should appear something like this---
Further resources
Upvotes: 0
Reputation: 986
Please try the below code
log_dir = '/gdrive/My Drive/project/' + "logs/fit/"
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
history = model.fit_generator(
train_generator,
steps_per_epoch=nb_train_samples // batch_size,
epochs=epochs,
validation_data=validation_generator,
validation_steps=nb_validation_samples // batch_size,
callbacks=[tensorboard_callback])
%load_ext tensorboard
%tensorboard --logdir /gdrive/My Drive/project/logs/fit/
Upvotes: 2