Windows 中的 Python Tensorflow Tensorboard

我在 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)的新手。


谢谢!


潇湘沐
浏览 193回答 1
1回答

有只小跳蛙

您的不是特定于 Windows 的 Tensorflow 错误。我已经使用您的代码进行了少量修改,现在我可以使用 Tensorboard 可视化模型性能。请参考下面的完整工作代码# Load the TensorBoard notebook extension%load_ext tensorboardimport tensorflow as tfprint(tf.__version__)import datetime, osfashion_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.0def create_model():&nbsp; return tf.keras.models.Sequential([&nbsp; &nbsp; tf.keras.layers.Flatten(input_shape=(28, 28)),&nbsp; &nbsp; tf.keras.layers.Dense(512, activation='relu'),&nbsp; &nbsp; tf.keras.layers.Dropout(0.2),&nbsp; &nbsp; tf.keras.layers.Dense(10, activation='softmax')&nbsp; ])def train_model():&nbsp; model = create_model()&nbsp; model.compile(optimizer='adam',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loss='sparse_categorical_crossentropy',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; metrics=['accuracy'])&nbsp; #NAME = "Trains_vs_Cars_16by2_CNN_{}".format(int(time.time()))&nbsp; NAME = "Trains_vs_Cars_16by2_{}".format(str(datetime.datetime.now()))&nbsp; tensorboard = tf.keras.callbacks.TensorBoard(log_dir="logs/{}".format(NAME))&nbsp; model.fit(x=x_train,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; y=y_train,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; batch_size=25,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; epochs=5,&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # validation_split=0.2,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; validation_data=(x_test, y_test),&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; callbacks=[tensorboard])train_model()%tensorboard --logdir logs输出:2.2.0Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz32768/29515 [=================================] - 0s 0us/stepDownloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz26427392/26421880 [==============================] - 0s 0us/stepDownloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz8192/5148 [===============================================] - 0s 0us/stepDownloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz4423680/4422102 [==============================] - 0s 0us/stepEpoch 1/52400/2400 [==============================] - 6s 3ms/step - loss: 0.4953 - accuracy: 0.8207 - val_loss: 0.4255 - val_accuracy: 0.8428Epoch 2/52400/2400 [==============================] - 6s 3ms/step - loss: 0.3851 - accuracy: 0.8589 - val_loss: 0.3715 - val_accuracy: 0.8649Epoch 3/52400/2400 [==============================] - 6s 3ms/step - loss: 0.3515 - accuracy: 0.8708 - val_loss: 0.3718 - val_accuracy: 0.8639Epoch 4/52400/2400 [==============================] - 6s 3ms/step - loss: 0.3315 - accuracy: 0.8771 - val_loss: 0.3649 - val_accuracy: 0.8686Epoch 5/52400/2400 [==============================] - 6s 3ms/step - loss: 0.3160 - accuracy: 0.8827 - val_loss: 0.3435 - val_accuracy: 0.8736有关更多详细信息,请参阅此处如果您遇到任何问题,请告诉我,我很乐意为您提供帮助。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python