NotFoundError: Failed to create a directory: logs/fit/-15 rain; No such file or

时间:2024-04-03 10:01:06

 最近在练习tensorflow2.0中的TensorBoard模块,原链接中的代码在jupyter notebook运行时出现了错误。虽暂时得到解决,但仍然不明原因,且记录如下:

原代码段1:

# 导入模块
import tensorflow as tf
import datetime

# 导入数据集
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'])

原代码段2(出现错误):

 

 

NotFoundError: Failed to create a directory: logs/fit/20190401-152011\train; No such file orNotFoundError: Failed to create a directory: logs/fit/20190401-152011\train; No such file or

偷懒式解决办法:

删除原代码中的log_dir路径,使用TensorBoard的默认路径 ’./logs‘,即可正常运行。

NotFoundError: Failed to create a directory: logs/fit/20190401-152011\train; No such file or