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
有关更多详细信息,请参阅此处
如果您遇到任何问题,请告诉我,我很乐意为您提供帮助。
添加回答
举报