为了账号安全,请及时绑定邮箱和手机立即绑定

Windows 中的 Python Tensorflow Tensorboard

Windows 中的 Python Tensorflow Tensorboard

潇湘沐 2022-05-24 16:26:08
我在 Windows 10 中使用带有 Python 3.7.4(64 位)的 Tensorflow。我已经建立了一个卷积神经网络模型,它在 Jupyter 中运行良好。现在我想用 Tensorboard 可视化它的性能。但是尝试设置它时,我收到一条错误消息。# Setting up Tensorboard to view model performance NAME = "Trains_vs_Cars_16by2_CNN_{}".format(int(time.time()))tensorboard = TensorBoard(log_dir="logs/{}".format(NAME))model.fit(X, y,      batch_size=25,      epochs=5,      validation_split=0.2,      callbacks=[tensorboard])# ERROR MESSAGE      NotFoundError                             Traceback (most recent call last)     <ipython-input-6-c627053c0717> in <module>     67           epochs=5,     68           validation_split=0.2,---> 69           callbacks=[tensorboard])此页面上的海报 ( https://github.com/tensorflow/tensorboard/issues/2023# ) 提到有一个特定于 Windows 的 Tensorflow 错误。这就是我遇到的吗?我是 TensorFlow(和 Python)的新手。谢谢!
查看完整描述

1 回答

?
有只小跳蛙

TA贡献1824条经验 获得超8个赞

您的不是特定于 Windows 的 Tensorflow 错误。我已经使用您的代码进行了少量修改,现在我可以使用 Tensorboard 可视化模型性能。


请参考下面的完整工作代码


# Load the TensorBoard notebook extension

%load_ext tensorboard


import tensorflow as tf

print(tf.__version__)

import datetime, os


fashion_mnist = tf.keras.datasets.fashion_mnist


(x_train, y_train),(x_test, y_test) = fashion_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')

  ])


def train_model():


  model = create_model()

  model.compile(optimizer='adam',

                loss='sparse_categorical_crossentropy',

                metrics=['accuracy'])


  #NAME = "Trains_vs_Cars_16by2_CNN_{}".format(int(time.time()))

  NAME = "Trains_vs_Cars_16by2_{}".format(str(datetime.datetime.now()))

  tensorboard = tf.keras.callbacks.TensorBoard(log_dir="logs/{}".format(NAME))


  model.fit(x=x_train, 

            y=y_train, 

            batch_size=25,

            epochs=5, 

            # validation_split=0.2,

            validation_data=(x_test, y_test), 

            callbacks=[tensorboard])


train_model()



%tensorboard --logdir logs

输出:


2.2.0

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz

32768/29515 [=================================] - 0s 0us/step

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz

26427392/26421880 [==============================] - 0s 0us/step

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz

8192/5148 [===============================================] - 0s 0us/step

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz

4423680/4422102 [==============================] - 0s 0us/step

Epoch 1/5

2400/2400 [==============================] - 6s 3ms/step - loss: 0.4953 - accuracy: 0.8207 - val_loss: 0.4255 - val_accuracy: 0.8428

Epoch 2/5

2400/2400 [==============================] - 6s 3ms/step - loss: 0.3851 - accuracy: 0.8589 - val_loss: 0.3715 - val_accuracy: 0.8649

Epoch 3/5

2400/2400 [==============================] - 6s 3ms/step - loss: 0.3515 - accuracy: 0.8708 - val_loss: 0.3718 - val_accuracy: 0.8639

Epoch 4/5

2400/2400 [==============================] - 6s 3ms/step - loss: 0.3315 - accuracy: 0.8771 - val_loss: 0.3649 - val_accuracy: 0.8686

Epoch 5/5

2400/2400 [==============================] - 6s 3ms/step - loss: 0.3160 - accuracy: 0.8827 - val_loss: 0.3435 - val_accuracy: 0.8736

//img1.sycdn.imooc.com//628c96c800014cb012410571.jpg

有关更多详细信息,请参阅此处


如果您遇到任何问题,请告诉我,我很乐意为您提供帮助。


查看完整回答
反对 回复 2022-05-24
  • 1 回答
  • 0 关注
  • 188 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信