MaidrCallback

keras.MaidrCallback(self, path=None, *, every=1, metrics=None)

Keep an accessible page of a model’s training curves while it trains.

Pass it to model.fit(callbacks=[...]). At the end of every every epochs it writes path again with the charts :func:plot_history draws, so a reader can open the page during a long run and reload it to hear how far the model has come. When training ends, the page is written a last time; with no path, the charts are shown in the notebook instead, if there is one.

Parameters

Name Type Description Default
path str or os.PathLike The HTML file to keep up to date. The page is replaced in one step, so a reload never meets a half-written file. A page that cannot be written, or drawn, is warned about, and training goes on. In multi-worker training, give each worker its own path, or the callback to one. None
every int Write the page every this many epochs. 1
metrics iterable of str Only these metrics, in this order, as for :func:plot_history. None

Attributes

Name Type Description
history dict of str to list of tuple Each metric’s values so far, as (epoch, value) pairs, epochs counted from 1. Reset when a new model.fit begins.

Raises

Name Type Description
ImportError If Keras is not installed.
ValueError If every is below 1.

Examples

>>> from maidr.keras import MaidrCallback
>>> model.fit(x, y, validation_split=0.2, epochs=50,
...           callbacks=[MaidrCallback("training.html", every=5)])

Methods

Name Description
figure Draw the curves recorded so far.
on_epoch_end Record the epoch’s metrics, and write the page every every epochs.
on_train_begin Start a new history, as each model.fit does.
on_train_end Write the page a last time, or show the charts in a notebook.

figure

keras.MaidrCallback.figure()

Draw the curves recorded so far.

Returns

Name Type Description
matplotlib.figure.Figure The charts :func:plot_history would draw for them.

on_epoch_end

keras.MaidrCallback.on_epoch_end(epoch, logs=None)

Record the epoch’s metrics, and write the page every every epochs.

Parameters

Name Type Description Default
epoch int The epoch that ended, counted from 0 as Keras passes it. required
logs mapping Each metric’s value at this epoch. A value that is not a single number is not recorded, with a warning the first time. None

on_train_begin

keras.MaidrCallback.on_train_begin(logs=None)

Start a new history, as each model.fit does.

Parameters

Name Type Description Default
logs mapping Passed by Keras; not read. None

on_train_end

keras.MaidrCallback.on_train_end(logs=None)

Write the page a last time, or show the charts in a notebook.

Parameters

Name Type Description Default
logs mapping Passed by Keras; not read. None