Colab 中的 Tensorboard:当前数据集没有处于活动状态的仪表板
Posted
技术标签:
【中文标题】Colab 中的 Tensorboard:当前数据集没有处于活动状态的仪表板【英文标题】:Tensorboard in Colab: No dashboards are active for the current data set 【发布时间】:2020-06-24 01:16:09 【问题描述】:我正在尝试在 Google Colab 中显示 Tensorboard。我导入tensorboard:%load_ext tensorboard
,然后创建一个log_dir
,适配如下:
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])
但是当我用%tensorboard --logdir logs/fit
调用它时,它不会显示。相反,它会抛出以下消息:
当前数据集没有处于活动状态的仪表板。
有解决办法吗?是我传入log_dir
的固定路径有问题吗?
【问题讨论】:
【参考方案1】:请尝试以下代码
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/
【讨论】:
【参考方案2】:也许您在某种程度上弄乱了路径。如果您使用的是 tensorflow 2.0+ 版本,请尝试使用此解决方案
## setup
# Load the TensorBoard notebook extension.
%load_ext tensorboard
导入必要的包
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."
你需要在你的model.fit()的callbacks参数中提供tensorboard_callbacks,它会看起来像这样--
# 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]))
这会将您的日志文件保存在您的 google colab notebook 中分配的内存中。
查看 TensorBoard 结果 --
%tensorboard --logdir logs/fit/
结果应该是这样的---
更多资源
https://www.tensorflow.org/tensorboard/scalars_and_keras【讨论】:
以上是关于Colab 中的 Tensorboard:当前数据集没有处于活动状态的仪表板的主要内容,如果未能解决你的问题,请参考以下文章
TensorFlow 1 中的 TensorBoard 使用 Google Colab
另一个 Chrome 选项卡中的 Google Colab TensorBoard
谷歌 colab 中用于 tensorflow-1.x 的 Tensorboard