Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Class

callbacks.CSVLogger

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.

How it works

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.

Syntax

keras.callbacks.CSVLogger(filename, separator=",", append=False)

Parameters

NameTypeDescription
filenamestringPath or name of the CSV output file, such as 'run/log.csv'.
separatorstringDelimiter placed between elements in the CSV file; defaults to ','.
appendbooleanWhether to append to an existing file; defaults to False, which overwrites it.

Returns

A CSVLogger callback object.

Key points

  • It records results at epoch granularity rather than writing a separate row for every batch.
  • Logged values must have a string representation that can be written to the CSV file.
  • One-dimensional iterables, including NumPy arrays, are among the supported value forms.
  • filename specifies the destination path and may include directories.
  • separator configures the delimiter used between CSV elements.
  • append=True is intended for resuming or extending a previous training log.

Common mistakes

  • The default append setting replaces an existing file, so enable append when continuing a prior log.

Example: Log training epochs to CSV

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.

When to use it

Track training history

You need a durable, spreadsheet-friendly record of losses and metrics from each training epoch.

Continue an existing log

A training run is resumed and its new epoch results should remain in the same log.

Produce custom-delimited output

A downstream parser expects a delimiter other than a comma.

Interview questions

QWhat does CSVLogger do and how is it used?

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.

QWhat constructor options does CSVLogger provide?

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.

QWhat kinds of values can CSVLogger record?

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.Callback
  • keras.callbacks.History
  • keras.callbacks.TensorBoard
  • keras.callbacks.ModelCheckpoint

Source: Keras documentation: CSVLogger. Checked 2026-10-15.