Keras提前停止回调错误,val_loss指标不可用
我正在训练Keras(在MacBook上为Tensorflow后端,Python),并且在fit_generator函数的早期停止回调中遇到错误.错误如下:
I am training a Keras (Tensorflow backend, Python, on MacBook) and am getting an error in the early stopping callback in fit_generator function. The error is as follows:
RuntimeWarning: Early stopping conditioned on metric `val_loss` which is not available. Available metrics are:
(self.monitor, ','.join(list(logs.keys()))),
RuntimeWarning: Can save best model only with val_acc available, skipping.
'skipping.' % (self.monitor), RuntimeWarning
[local-dir]/lib/python3.6/site-packages/keras/callbacks.py:497: RuntimeWarning: Early stopping conditioned on metric `val_loss` which is not available. Available metrics are:
(self.monitor, ','.join(list(logs.keys()))), RuntimeWarning
[local-dir]/lib/python3.6/site-packages/keras/callbacks.py:406: RuntimeWarning: Can save best model only with val_acc available, skipping.
'skipping.' % (self.monitor), RuntimeWarning)
Traceback (most recent call last):
:
[my-code]
:
File "[local-dir]/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "[local-dir]/lib/python3.6/site-packages/keras/engine/training.py", line 2213, in fit_generator
callbacks.on_epoch_end(epoch, epoch_logs)
File "[local-dir]/lib/python3.6/site-packages/keras/callbacks.py", line 76, in on_epoch_end
callback.on_epoch_end(epoch, logs)
File "[local-dir]/lib/python3.6/site-packages/keras/callbacks.py", line 310, in on_epoch_end
self.progbar.update(self.seen, self.log_values, force=True)
AttributeError: 'ProgbarLogger' object has no attribute 'log_values'
我的代码如下(看起来不错):
My code is as follows (which looks OK):
:
ES = EarlyStopping(monitor="val_loss", min_delta=0.001, patience=3, mode="min", verbose=1)
:
self.model.fit_generator(
generator = train_batch,
validation_data = valid_batch,
validation_steps = validation_steps,
steps_per_epoch = steps_per_epoch,
epochs = epochs,
callbacks = [ES],
verbose = 1,
workers = 3,
max_queue_size = 8)
该错误消息似乎与提早停止的回调有关,但该回调看起来不错.该错误还指出val_loss不适合,但我不确定为什么...与此有关的另一件不寻常的事情是,该错误仅在使用较小的数据集时发生.
The error message appears to relate to the early stopping callback but the callback looks OK. Also the error states that the val_loss is not appropriate, but I am not sure why... one more unusual thing about this is that the error only occurs when I use smaller data sets.
感谢您的帮助.
如果仅在使用较小的数据集时才发生错误,则很有可能使用的数据集足够小而在验证集中没有单个样本.
If the error only occurs when you use smaller datasets, you're very likely using datasets small enough to not have a single sample in the validation set.
因此,它无法计算验证损失.
Thus it cannot calculate a validation loss.