What is model-best.h5

Hi, I see that there is a model-best.h5 saved under files in each run. Is that model saved at the end or is it saved at the epoch where the metric in goal is at it’s peak performance? Thank you

Hi @ridhanya

This depends on how you are saving the model.

The model-best.h5 file that you see under the Files tab in each run is typically saved when using the WandbCallback with Keras (unless you are using a specific integration, if yes which one?)

This file represents the best version of the model according to a specified metric during training, not necessarily at the end of training. The WandbCallback can be configured to monitor a specific metric, such as validation accuracy, and save the model weights when that metric is at its peak performance.

Here’s how you can set up the WandbCallback to save the best model:

import wandb
from wandb.keras import WandbCallback

# Initialize a new W&B run

# Add the WandbCallback to your Keras model's fit function
model.fit(X_train, y_train, validation_data=(X_val, y_val),
          callbacks=[WandbCallback(monitor='val_accuracy', mode='max', save_model=True)])

In this example, the WandbCallback is monitoring the val_accuracy metric, and it’s set to save the model weights (save_model=True) when it observes the best value for this metric (mode='max'). The saved model will be named model-best.h5 by default.

1 Like

Hi @ridhanya , since we have not heard back from you we are going to close this request. If you would like to re-open the conversation, please let us know!