In this tutorial, we'll show you show to save and plot the history of the performance of a Keras model over time, using Weights & Biases.
By default Keras' model.fit() returns a History callback object. This object keeps track of the accuracy, loss and other training metrics, for each epoch, in the memory.
You can access the data in the history object like so –
hist = model.fit(X_train, y_train,
So, what's in the history? We can access the metrics collected in the history object by accessing its keys.
# Output: dict_keys(['loss', 'acc', 'val_loss', 'val_acc', 'lr'])
The dictionary values would be hard to parse as text, so next up let's visualize the data collected by the history object.
Normally, we'd do this in a convoluted way by making custom matplotlib plots. There are a couple reasons this is untenable –
This process quickly gets unwieldy if we're training more than a few models, or collaborating with other people.
Weights & Biases makes it super easy to visualize the history automatically. You can simply add a WandbCallback to your model.fit() to automatically save all the metrics and the loss values tracked. Check out the docs for more info.
from wandb.keras import WandbCallback
# 1. Start a new run
# ... Define a model
# 2. Log layer dimensions and metrics over time
model.fit(X_train, y_train, validation_data=(X_test, y_test),
In the plots below, you can see all the metrics collected by the history object visualized by Weights & Biases with just a couple line of code.