模型检查点未创建目录

模型检查点未创建目录

本文介绍了模型检查点未创建目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习有关在Keras中保存模型的知识,并且看来我的模型检查点对象未创建指定的目录.这是代码:

I was learning about model saving in Keras, and it seems like my model checkpoint object doesn't create the specified directory. Here is the code:

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

这可能是什么原因?顺便说一句,我不在本地计算机上执行此操作.我使用Google Colab.

What could be the reason for this?Btw I am not doing this on my local machine. I use Google Colab.

推荐答案

keras中的 ModelCheckpoint 不会创建任何目录.您必须在训练模型之前创建文件夹 model_checkpoints_5000 ,否则在完成一个返回如下错误的纪元后,它将无法保存模型:

The ModelCheckpoint in keras does not create any directory. You have to create the folder model_checkpoints_5000 before training the model, otherwise it will fail to save the model after finishing an epoch returning an error like this:

tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: model_checkpoints_5000/XXX; No such file or directory

这篇关于模型检查点未创建目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 13:19