首页 > 解决方案 > 无法在 Modelcheckpoint 中创建文件和使用文件路径

问题描述

我在这里关注这个超级好的教程https://dashee87.github.io/data%20science/deep%20learning/python/another-keras-tutorial-for-neural-network-beginners/

但是,我无法正确使用 Modelcheckpoint 中的文件路径。

filepath="C:/Users/Thomas01/Documents/pimaindiansdiabetescsv/nnweights- 
{epoch:02d}.hdf5"
checkpoint = keras.callbacks.ModelCheckpoint(filepath, monitor='val_acc', 
verbose=0, save_weights_only=False, save_best_only=False, mode='max') 

[...]

temp_test_model.load_weights("C:/Users/Thomas01/Documents/pimaindiansdiabetescsv/nnweights-%02d.hdf5" % i)

[...]

我得到:

OSError:无法打开文件(无法打开文件:名称 = 'C:/Users/Thomas01/Documents/pimaindiansdiabetescsv/nnweights-00.hdf5',errno = 2,错误消息 = '没有这样的文件或目录',标志 = 0, o_flags = 0)

尝试使用原始字符串(但我认为我丢失了参数说明符?),或 \,但没有一个工作。

标签: keras

解决方案


设置verbose=1看看它保存在哪里

checkpoint = keras.callbacks.ModelCheckpoint(filepath, monitor='val_acc', verbose=1, save_weights_only=False, save_best_only=False, mode='max') 

# Epoch 00001: val_acc improved from -inf to 0.53781, saving model to /yourpath/yourpath

推荐阅读