python - Keras 模型检查点保存期间出错 : 'OSError: Unable to create file. Permission denied'

标签 python keras conv-neural-network

在我的 CNN 的第 57 纪元附近,保存模型检查点时,我收到一条错误消息:

OSError: Unable to create file (unable to open file: name = 'BestF1_SMOTE_UP_Transf.hdf5'

问题是,到目前为止,模型正在保存查找。只需查看输出,它就在大约 15 个检查点处保存了模型。然后突然它停止工作了。

我不知道该尝试什么,我很困惑。因为到目前为止它工作得很好。在 56 和 57 纪元之间发生了一些事情。通过谷歌搜索这个问题,我发现有人降级了 Keras 版本,但这有点激烈。过去几个月我一直在保存模型,没有出现任何问题。事实上,我的其他型号现在保存得很好。只是这个特定的..(如果重要的话,我正在使用 VGGnet 作为特征提取器)。

有问题的文件名和检查点:

save_path = 'BestF1_SMOTE_UP_Transf.hdf5'

# save highest F1 out of all epochs 

checkpoint = ModelCheckpoint(save_path, 
                             monitor='val_f1_score',
                             verbose=1, save_best_only=True,
                             mode='max')

# reduce learning rate if F1 stagnates

reduce_lr = ReduceLROnPlateau(monitor='val_f1_score',
                              factor=0.2,patience=5,
                              min_lr=0.0001)

historynew = model.fit(train_features_vgg,ytrain,
                       batch_size=batch_size,
                       callbacks=[reduce_lr,checkpoint],
                       epochs=400,
                       validation_data=(validation_features_vgg, ytest),
                       verbose=1)

此处完整回溯:

Epoch 00056: val_f1_score improved from 0.92658 to 0.92772, saving model to BestF1_SMOTE_UP_Transf.hdf5
Epoch 57/400
14243/14243 [==============================] - 5s 321us/step - loss: 0.0125 - auroc: 1.0000 - precision: 0.9965 - recall: 0.9980 - f1_score: 0.9973 - val_loss: 0.4475 - val_auroc: 0.9607 - val_precision: 0.9149 - val_recall: 0.9434 - val_f1_score: 0.9289

Epoch 00057: val_f1_score improved from 0.92772 to 0.92892, saving model to BestF1_SMOTE_UP_Transf.hdf5
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-38-9b31dbe220b2> in <module>
      9 reduce_lr = ReduceLROnPlateau(monitor='val_f1_score', factor=0.2,patience=5, min_lr=0.0001)
     10 
---> 11 historynew = model.fit(train_features_vgg,ytrain, batch_size=batch_size,callbacks=[reduce_lr,checkpoint],epochs=400,validation_data=(validation_features_vgg, ytest),verbose=1)
     12 

~\Anaconda3\envs\Tensorflow\lib\site-packages\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
   1037                                         initial_epoch=initial_epoch,
   1038                                         steps_per_epoch=steps_per_epoch,
-> 1039                                         validation_steps=validation_steps)
   1040 
   1041     def evaluate(self, x=None, y=None,

~\Anaconda3\envs\Tensorflow\lib\site-packages\keras\engine\training_arrays.py in fit_loop(model, f, ins, out_labels, batch_size, epochs, verbose, callbacks, val_f, val_ins, shuffle, callback_metrics, initial_epoch, steps_per_epoch, validation_steps)
    215                         for l, o in zip(out_labels, val_outs):
    216                             epoch_logs['val_' + l] = o
--> 217         callbacks.on_epoch_end(epoch, epoch_logs)
    218         if callback_model.stop_training:
    219             break

~\Anaconda3\envs\Tensorflow\lib\site-packages\keras\callbacks.py in on_epoch_end(self, epoch, logs)
     77         logs = logs or {}
     78         for callback in self.callbacks:
---> 79             callback.on_epoch_end(epoch, logs)
     80 
     81     def on_batch_begin(self, batch, logs=None):

~\Anaconda3\envs\Tensorflow\lib\site-packages\keras\callbacks.py in on_epoch_end(self, epoch, logs)
    444                             self.model.save_weights(filepath, overwrite=True)
    445                         else:
--> 446                             self.model.save(filepath, overwrite=True)
    447                     else:
    448                         if self.verbose > 0:

~\Anaconda3\envs\Tensorflow\lib\site-packages\keras\engine\network.py in save(self, filepath, overwrite, include_optimizer)
   1088             raise NotImplementedError
   1089         from ..models import save_model
-> 1090         save_model(self, filepath, overwrite, include_optimizer)
   1091 
   1092     def save_weights(self, filepath, overwrite=True):

~\Anaconda3\envs\Tensorflow\lib\site-packages\keras\engine\saving.py in save_model(model, filepath, overwrite, include_optimizer)
    377         opened_new_file = False
    378 
--> 379     f = h5dict(filepath, mode='w')
    380 
    381     try:

~\Anaconda3\envs\Tensorflow\lib\site-packages\keras\utils\io_utils.py in __init__(self, path, mode)
    184             self._is_file = False
    185         elif isinstance(path, str):
--> 186             self.data = h5py.File(path, mode=mode)
    187             self._is_file = True
    188         elif isinstance(path, dict):

~\Anaconda3\envs\Tensorflow\lib\site-packages\h5py\_hl\files.py in __init__(self, name, mode, driver, libver, userblock_size, swmr, **kwds)
    310             with phil:
    311                 fapl = make_fapl(driver, libver, **kwds)
--> 312                 fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
    313 
    314                 if swmr_support:

~\Anaconda3\envs\Tensorflow\lib\site-packages\h5py\_hl\files.py in make_fid(name, mode, userblock_size, fapl, fcpl, swmr)
    146         fid = h5f.create(name, h5f.ACC_EXCL, fapl=fapl, fcpl=fcpl)
    147     elif mode == 'w':
--> 148         fid = h5f.create(name, h5f.ACC_TRUNC, fapl=fapl, fcpl=fcpl)
    149     elif mode == 'a':
    150         # Open in append mode (read/write).

h5py\_objects.pyx in h5py._objects.with_phil.wrapper()

h5py\_objects.pyx in h5py._objects.with_phil.wrapper()

h5py\h5f.pyx in h5py.h5f.create()

OSError: Unable to create file (unable to open file: name = 'BestF1_SMOTE_UP_Transf.hdf5', errno = 13, error message = 'Permission denied', flags = 13, o_flags = 302)

最佳答案

我通过输入 admin CMD 解决了这个问题。

关于python - Keras 模型检查点保存期间出错 : 'OSError: Unable to create file. Permission denied' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55749070/

相关文章:

python - 用 PyTorch 绘制函数的导数?

python - XGBoost - xgb.cv 和 cross_val_score 之间的巨大差异

keras - ValueError :Layer conv1d was called with an input that isn't a symbolic tensor. 该层的所有输入都应该是张量

python - 大 HDF5 数据集,如何在每个纪元后高效地洗牌

deep-learning - caffe:“分组”参数是什么意思?

python - 如何优化这个 MaxPool2d 实现

python - 如果两个 SQLAlchemy 查询相同,如何比较它们?

python - 在创建自定义层时,当在 Keras 中调用构建方法时

parallel-processing - torch.nn.DataParallel 如何改变输出大小?

python - scipy.stats 中 cdf 的精度