在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)
答案 0 :(得分:0)
我通过输入admin CMD解决了这个问题。
答案 1 :(得分:0)
请使用文件扩展名“ .h5”作为检查点文件名。我刚刚遇到了相同的错误消息,并通过它解决了该问题。
我遵循了the TensorFlow Keras tutorial中使用.h5的指令。