KeyError:无法设置此回调文件路径的格式 [英] KeyError: Failed to format this callback filepath

查看:281
本文介绍了KeyError:无法设置此回调文件路径的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图获得验证准确性并选择保存具有最佳准确性的模型.但是在第一个时期之后,它显示了检查点错误.

I am trying to obtain the validation accuracy and the choose to save the model having the best accuracy.But after the 1st epoch,it is showing the checkpoint error.

filepath="tumor_detection-{epoch:02d}-{val_acc:.2f}.hdf5"

# save the model with the best validation (development) accuracy till now
checkpoint = ModelCheckpoint(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max')

%%time
model.fit(xtrain,ytrain,batch_size=32,epochs=30,validation_data=(xval,yval),callbacks=[checkpoint])```

It is then showing an error as follows:
Epoch 1/30
51/51 [==============================] - ETA: 0s - loss: 0.4651 - accuracy: 0.7725
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/callbacks.py in _get_file_path(self, epoch, logs)
   1243         # placeholders can cause formatting to fail.
-> 1244         return self.filepath.format(epoch=epoch + 1, **logs)
   1245       except KeyError as e:

KeyError: 'val_acc'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
9 frames
<decorator-gen-60> in time(self, line, cell, local_ns)

<timed eval> in <module>()

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/callbacks.py in _get_file_path(self, epoch, logs)
   1245       except KeyError as e:
   1246         raise KeyError('Failed to format this callback filepath: "{}". '
-> 1247                        'Reason: {}'.format(self.filepath, e))
   1248     else:
   1249       # If this is multi-worker training, and this worker should not

KeyError: 'Failed to format this callback filepath: "tumor_detection-{epoch:02d}-{val_acc:.2f}.hdf5". Reason: \'val_acc\'

推荐答案

同时替换

'val_acc'

在file_path和检查点中

in file_path and checkpoint with

'val_accuracy'

它将起作用.

这篇关于KeyError:无法设置此回调文件路径的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆