tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: ../user_data\co

every blog every motto: You will never know unless you try

0. 前言

有关tensorboard遇到的问题
废话: 之前明明好好的,不知道今天为啥抽风了。

1. 正文

部分代码如下

tensorboard_dir = os.path.join('../', 'user_data', 'code2_output', 'tensorboard')
if not os.path.exists(tensorboard_dir):
    os.makedirs((tensorboard_dir))

# 回调函数
callbacks = [
    TensorBoard(log_dir=tensorboard_dir),
    ModelCheckpoint(output_model_file, save_best_only=True, save_freq='epoch'),  # 保存模型频率
    ReduceLROnPlateau(factor=0.5, patience=3),  # 学效率下降
    EarlyStopping(min_delta=1e-3, patience=10)  # 早停
  ]

报错如下:

tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: ../user_data\code2_output\tensorboard\train\plugins\profile\2021-02-06_21-57-28; No such file or directory

解决方法

  1. 手动建立保存tensorboard文件夹
  2. 文件夹用logs,而不是我上面代码那样,如下代码
  3. 文件夹用os.path.join连接,如上代码
  4. 目录文件夹用“\”,而不是“/”

tensorboard_dir = os.path.join('../', 'user_data', 'code2_output', 'logs')

说明

我是用上面的第4个方法解决的
如下代码测试都可以

tensorboard_dir = os.path.join('..\\user_data\\code2_output\\tensorboard')
tensorboard_dir = os.path.join(r'..\user_data\code2_output\tensorboard')
tensorboard_dir = os.path.join('..\\', 'user_data', 'code2_output', 'tensorboard')

参考文献

[1] https://stackoom.com/question/3xL0g/%E5%A6%82%E4%BD%95%E4%B8%BA%E6%88%91%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%88%9B%E5%BB%BATensorboard
[2] https://github.com/ibab/tensorflow-wavenet/issues/255
[3] https://stackoverflow.com/questions/49043393/tensorflow-python-framework-errors-impl-notfounderror-failed-to-create-a-direct
[4] https://blog.csdn.net/tz_zs/article/details/76566002

你可能感兴趣的:(问题)