python - 模型检查点不创建目录
问题描述
我正在学习如何在 Keras 中保存模型,看起来我的模型检查点对象没有创建指定的目录。这是代码:
from tensorflow.keras.callbacks import ModelCheckpoint
checkpoint_5000_path = \
'model_checkpoints_5000/checkpoint_{epoch:02d}_{batch:04d}'
checkpoint_5000 = ModelCheckpoint(filepath=checkpoint_5000_path,
save_freq=5000,
save_weights_only=True,
verbose=2)
model = get_new_model()
model.fit(x_train,y_train,epochs=10,validation_split=0.15,callbacks=[checkpoint_5000],verbose=2)
当我尝试访问目录时,
! ls -lh model_checkpoints_5000
出现此错误。
ls: cannot access 'model_checkpoints_5000': No such file or directory
这可能是什么原因?顺便说一句,我没有在我的本地机器上这样做。我使用谷歌 Colab。
解决方案
在ModelCheckpoint
keras 中不会创建任何目录。您必须model_checkpoints_5000
在训练模型之前创建文件夹,否则在完成一个 epoch 后将无法保存模型,返回如下错误:
tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: model_checkpoints_5000/XXX; No such file or directory
推荐阅读
- html - 如何使boostrap4列适合其内容
- python-3.x - 使用 Scapy 端口扫描器查找监听端口的网络服务器
- c# - 如何使用 Winform C# 在 ListView 中为消息制作多行文本?
- javascript - 有没有办法在动态 URL 上允许 Google OAuth?
- php - 两个php对象,使用另一个函数?对象变量范围?
- rxjs - 完成后重复或重新启动一个可观察的(间隔)
- string - 将方程输入作为字符串,然后用 popen() 和 bc 求解
- java - 如何修复“线程“主”java.io.IOException中的异常:服务器返回HTTP响应代码:URL 403”错误?
- python-3.x - 如何格式化来自python 3中数据库表的日期时间?
- javascript - 反应原生
没有出现在屏幕上