Solution suggested here did not solve my problem this question.
I'm trying to use callbacks ModelCheckpoint
and EarlyStopping to save the best weights when early stopping. After the first epoch I get a runtime warning but the codes runs the remaining epochs without errors, but still no file containing weight appears. The warning after the first epoch is the following:
RuntimeWarning: Can save best model only with val_acc available, skipping. 'skipping.' % (self.monitor), RuntimeWarning) RuntimeWarning: Early stopping conditioned on metric
val_acc
which is not available. Available metrics are: val_loss,val_accuracy,loss,accuracy (self.monitor, ','.join(list(logs.keys()))), RuntimeWarning
I have validation data added to the fit()
function so I'm not sure why.
filepath = "weights_best.hdf5"
model.compile(loss="mean_squared_error",
metrics=['accuracy'],
optimizer=optimizer)
batchSize = 64
numEpochs = 75
validation_data = (data.x_valid, data.y_valid)
callbackCheckpoint = keras.callbacks.callbacks.ModelCheckpoint(filepath,
monitor='val_acc',
save_best_only=True,
save_weights_only= True,
mode='max')
callbackEarlyStop = keras.callbacks.callbacks.EarlyStopping(monitor='val_acc',
min_delta=0,
patience=7,
verbose=0,
mode='auto')
callbacks = [callbackCheckpoint, callbackEarlyStop]
model.fit(data.x_train, data.y_train, batchSize, numEpochs, callbacks=callbacks,
validation_data=validation_data)
Any help would be greatly appreciated!
fit
? Ifval_acc
is there then I'd suggest you change the Keras and Tensorflow version, the code doesn't look like there's any problem. – Natthaphon Hongcharoen45000/45000 [==============================] - 126s 3ms/step - loss: 0.1793 - accuracy: 0.0993 - val_loss: 0.1806 - val_accuracy: 0.0968
, so yes,val_acc
is present! I'll give it a try. – JustAnotherUserval_accuracy
notval_acc
. Change that!! – Natthaphon Hongcharoenmonitor='val_acc'
tomonitor='val_accuracy'
ormetrics=['accuracy']
tometrics=['acc']
– Natthaphon Hongcharoen