saving best model only using modelcheckpoint keras
while using model.fit for training a Transformer model, how to use `tf.keras.callbacks.ModelCheckpoint` with `'save_best_only=True'` to save only the best model?

`model.fit([input_ids_train, attention_mask_train], train_labels,
          validation_data=([input_ids_valid, attention_mask_valid], valid_labels),
          epochs=50, batch_size=32)`

Have you taken a look at the [Keras docs](https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/ModelCheckpoint)?<|||||>This issue has been automatically marked as stale and been closed because it has not had recent activity. Thank you for your contributions.

If you think this still needs to be addressed please comment on this thread.<|||||>@LysandreJik  Yes i looked the following doc and implemented it.

```
config = AutoConfig.from_pretrained(
    PRETRAINED_MODEL_VERSION, num_labels=len(classes), label2id=label2id, id2label=id2label,
    finetuning_task="text-classification")
model = TFAutoModelForSequenceClassification.from_pretrained(PRETRAINED_MODEL_VERSION, config=config)

loss = tf.keras.losses.CategoricalCrossentropy(from_logits=True)
metric = tf.keras.metrics.Accuracy()
optimizer = tf.keras.optimizers.Adam(learning_rate=2e-6, epsilon=1e-08)
model.compile(loss=loss, optimizer=optimizer, metrics=[metric])
print(model.summary())

es_callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=3, verbose=1)
chkpt_calllback = tf.keras.callbacks.ModelCheckpoint(MODEL_DIRECTORY+"{epoch:02d}",
                                                     monitor='val_loss', verbose=2,
                                                     save_best_only=True, save_weights_only=False)

model.fit([input_ids_train, attention_mask_train], train_labels,
          validation_data=([input_ids_valid, attention_mask_valid], valid_labels),
          epochs=1, batch_size=32, callbacks=[es_callback, chkpt_calllback])
```
but doing so saves the model checkpoint only and I'm not sure how to load these weights again into the **model**. As it only accepts **.h5** format. Facing difficulty in loading these weights
```
checkpoint
02.index
02.data-00000-of-00001
```