gpt4 book ai didi

python - (https ://www. tensorflow.org/tensorboard/get_started) 上的 Tensorboard 2.1.0 示例无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-03 19:50:09 26 4
gpt4 key购买 nike

我正在使用 Win10Pro、gpu (CUDA 10.1)、Python 3.7.5、Tensorflow 2.1.0 和 Tensorboard 2.1.0 在 ipython 中使用以下代码运行 ( https://www.tensorflow.org/tensorboard/get_started ) 上给出的张量板示例(运行后 < em>%load_ext tensorboard 在 ipython 控制台中):

import tensorflow as tf
import datetime
import os
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')
])
model = create_model()
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

log_dir=os.path.join("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])

运行成功。之后,我在命令提示符中输入 (%tensorboard --logdir logs/fit) 并收到以下消息:

2020-01-24 11:40:14.612500: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll W0124 11:40:16.549416 8508 plugin_event_accumulator.py:294] Found more than one graph event per run, or there was a metagraph containing a graph_def, as well as one or more graph events. Overwriting the graph with the newest event. Serving TensorBoard on localhost; to expose to the network, use a proxy or pass --bind_all TensorBoard 2.1.0 at http://localhost:6006/ (Press CTRL+C to quit).

然而,当我去上述地址时,却没有看到任何东西。我的日志目录有一个绝对路径:C:\Users\ak39.MEDMA\codes\logs\fit。谁能帮我可视化 Tensorboard 吗?

最佳答案

您可以尝试以下操作:在顶部添加导入

from tensorflow.keras.callbacks import TensorBoard, LearningRateScheduler

向回调添加更新频率

tensorboard_callback = TensorBoard(
log_dir=log_dir,
update_freq='batch',
histogram_freq=1)

此外,在 tensorflow 指南( https://www.tensorflow.org/tensorboard/get_started )中,建议在命令行中运行时启动不带 % 的张量板。

tensorboard --logdir logs/fit

如果这不起作用,那么您还可以尝试通过添加检查点回调在每个纪元之后保存检查点:

checkpoint_callback = ModelCheckpoint(
filepath, monitor='val_accuracy', verbose=1,
save_best_only=False, save_weights_only=False,
save_frequency=1)

示例:

model.fit(train_dataset,
epochs=3, callbacks=[checkpoint_callback],
validation_data=test_dataset,
validation_freq=1)

关于python - (https ://www. tensorflow.org/tensorboard/get_started) 上的 Tensorboard 2.1.0 示例无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59895151/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com