python - Keras 无法使用回调来存储检查点

标签 python machine-learning keras

train_data = ImageDataGenerator(rescale=1./255)
test_data = ImageDataGenerator(rescale=1./255)
train_set = train_data.flow_from_directory('train_set',
                                           target_size=(28,28),
                                           batch_size=16,
                                           class_mode='categorical')
test_set = train_data.flow_from_directory('test_set',
                                           target_size=(28,28),
                                           batch_size = 16,
                                           class_mode='categorical')
checkpointer = ModelCheckpoint(filepath="best_weight.hdf5",
                               monitor='val_acc',
                               verbose=1,
                               save_best_only=True)
history = classifier.fit_generator(train_set,
                                   steps_per_epoch=210,
                                   epochs=5,
                                   callbacks=[checkpointer],
                                   validation_data=test_set,
                                   validation_steps=90)

classifier.load_weights('best_weights.hdf5')

当我尝试加载最佳权重时,它显示没有这样的文件或目录。我应该如何做出改变?非常感谢你们!

最佳答案

您的文件名有拼写错误;您保存在

filepath="best_weight.hdf5"

当您尝试加载'best_weights.hdf5'时。

删除文件名中最后的s,即:

classifier.load_weights('best_weight.hdf5')

关于python - Keras 无法使用回调来存储检查点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58054115/

相关文章:

python - 从 csv 文件中删除具有特定值的所有行

将在给定字符串中查找和计算元音的 Python 函数

windows - 相同的代码,在 windows/ubuntu (Keras/Tensorflow) 上的准确性非常不同

python-3.x - 如何从 Chollet Deep Learning with Python 中解决 KeyError : 'val_mean_absolute_error' Keras 2. 3.1 和 TensorFlow 2.0

python - 在Tensorflow.keras 2.0中,当一个模型有多个输出时,如何为model.fit()定义一个灵活的损失函数?

python - Pandas 根据列将两行合并为一行

python - Flask 的 UserMixin 在 Django 中的等价物是什么?

TensorFlow - "TypeError: Fetch Argument None"

python - 如何在 TensorFlow 中将字符串标签转换为单热向量?

machine-learning - 我有一个数据集,我想使用 NLP 进行短语提取,但我无法这样做?