Track training history
You need a durable, spreadsheet-friendly record of losses and metrics from each training epoch.
Keras · Class
CSVLogger records epoch results from model training in a CSV file. You can choose the output path, delimiter, and whether existing logs are appended or overwritten.
CSVLogger writes epoch-level training results to a CSV file during model training. Configure the destination, field separator, and whether an existing file should be extended or replaced.
keras.callbacks.CSVLogger(filename, separator=",", append=False)| Name | Type | Description |
|---|---|---|
filename | string | Path or name of the CSV output file, such as 'run/log.csv'. |
separator | string | Delimiter placed between elements in the CSV file; defaults to ','. |
append | boolean | Whether to append to an existing file; defaults to False, which overwrites it. |
A CSVLogger callback object.
import keras
import numpy as np
x = np.random.rand(32, 4)
y = np.random.rand(32, 1)
model = keras.Sequential([keras.layers.Dense(1, input_shape=(4,))])
model.compile(optimizer="adam", loss="mse")
model.fit(x, y, epochs=2, callbacks=[keras.callbacks.CSVLogger("training.csv")])Trains the model while recording each epoch's results in training.csv.
You need a durable, spreadsheet-friendly record of losses and metrics from each training epoch.
A training run is resumed and its new epoch results should remain in the same log.
A downstream parser expects a delimiter other than a comma.
CSVLogger is a callback that streams epoch results to a CSV file. Pass it in the callbacks list supplied to model.fit().
Follow-up: How would you continue an existing log? Set append=True so an existing file is extended instead of overwritten.
filename identifies the output CSV, separator controls how fields are separated, and append determines whether an existing file is preserved. The default separator is a comma and the default append value is False.
Follow-up: When would separator be useful? Use it when another consumer expects a delimiter other than a comma.
The callback supports values that can be represented as strings, including one-dimensional iterables such as NumPy arrays. This lets logged epoch results include those supported values in the CSV output.
Follow-up: What limitation follows from this behavior? Values that cannot be represented as strings are not suitable for this logger's CSV representation.
keras.callbacks.Callbackkeras.callbacks.Historykeras.callbacks.TensorBoardkeras.callbacks.ModelCheckpoint