Early stop using validation callback

I'm trying to callback with validation (val_loss) but validation is not taking place. this warning is shown "WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy"

`check=callbacks.EarlyStopping(monitor='val_accuracy', mode='auto',patience=2,verbose=1)
 
 history = model.fit(train_dataset,
                          steps_per_epoch=163,
                          epochs=10,
                          validation_data=val_dataset,
                          validation_steps=624,
                          callbacks = [check])`

Upvotes: 2

Views: 1943

Answers (1)

user11530462
user11530462

Reputation:

Providing the solution here (Answer Section) even though it is present in the Comments Section for the benefit of the Community.

The above code which comprises Early Stopping and model.fit works fine if we remove the argument, validation_steps.

Working code is shown below:

check=callbacks.EarlyStopping(monitor='val_accuracy', mode='auto',patience=2,verbose=1)
 

history = model.fit(train_dataset,
                              steps_per_epoch=163,
                              epochs=10,
                              validation_data=val_dataset,
                              callbacks = [check])

The reason can be understood from the Tensorflow Documentation corresponding to the argument, validation_steps as shown below:

validation_steps: Only relevant if validation_data is provided and is a tf.data dataset. Total number of steps (batches of samples) to draw before stopping when performing validation at the end of every epoch. If 'validation_steps' is None, validation will run until the validation_data dataset is exhausted. In the case of an infinitely repeated dataset, it will run into an infinite loop. If 'validation_steps' is specified and only part of the dataset will be consumed, the evaluation will start from the beginning of the dataset at each epoch. This ensures that the same validation samples are used every time.

Upvotes: 2

Related Questions