WARNING:tensorflow:Can save best model only with val_accuracy available, skipping

2.5k views Asked by At

Previously(about 3 months ago) this worked without issues. However when i tried to run this recently i got a warning "WARNING:tensorflow:Can save best model only with val_accuracy available, skipping" and it doesn't print val_accuracy. Can someone plz help?

model.compile(loss="categorical_crossentropy", 
              optimizer=opt,
              metrics=['accuracy'])

checkpoint_filepath='/tmp/checkpoint'
checkpoint= keras.callbacks.ModelCheckpoint(filepath= checkpoint_filepath, 
                                               verbose=0, 
                                               save_weights_only=False, 
                                               mode='auto',
                                               monitor='val_accuracy', 
                                               save_best_only=True)

print("[INFO] training head...")

history = model.fit(
                trainAug.flow(np.array(trainX), np.array(trainY), batch_size=batch_size),
                steps_per_epoch=len(trainX) // batch_size,
                validation_data=(np.array(testX), np.array(testY),),
                validation_steps=len(testX) // batch_size,
                callbacks=[checkpoint],
                epochs=20)
1

There are 1 answers

0
Danilo Santana On

I had the same issue, but I just configured it like this:

checkpoint= keras.callbacks.ModelCheckpoint(filepath= checkpoint_filepath, verbose=1, save_freq="epoch", mode='auto',monitor='val_loss', save_best_only=True)

include save_freq="epoch", you can use monitor='val_loss".

In my case everything was all right!