code: def test_CSVLogger(self):
      OUTPUT_DIM = 1
      np.random.seed(1337)
      temp_dir = tempfile.TemporaryDirectory()
      filepath = os.path.join(temp_dir.name, "log.tsv")
  
      sep = "\t"
      x_train = np.random.random((TRAIN_SAMPLES, INPUT_DIM))
      y_train = np.random.random((TRAIN_SAMPLES, OUTPUT_DIM))
      x_test = np.random.random((TEST_SAMPLES, INPUT_DIM))
      y_test = np.random.random((TEST_SAMPLES, OUTPUT_DIM))
  
      def make_model():
          np.random.seed(1337)
          model = Sequential(
              [
                  layers.Dense(2, activation="relu"),
                  layers.Dense(OUTPUT_DIM),
              ]
          )
          model.compile(
              loss="mse",
              optimizer="sgd",
              metrics=["mse"],
          )
          return model
  
      # case 1, create new file with defined separator
      model = make_model()
      cbks = [callbacks.CSVLogger(filepath, separator=sep)]
      model.fit(
          x_train,
          y_train,
          batch_size=BATCH_SIZE,
          validation_data=(x_test, y_test),
          callbacks=cbks,
          epochs=1,
          verbose=0,
      )
  
      assert os.path.exists(filepath)
      with open(filepath) as csvfile:
          dialect = csv.Sniffer().sniff(csvfile.read())
      assert dialect.delimiter == sep
      del model
      del cbks
  
      # case 2, append data to existing file, skip header
      model = make_model()
      cbks = [callbacks.CSVLogger(filepath, separator=sep, append=True)]
      model.fit(
          x_train,
          y_train,
          batch_size=BATCH_SIZE,
          validation_data=(x_test, y_test),
          callbacks=cbks,
          epochs=1,
          verbose=0,
      )
  
      # case 3, reuse of CSVLogger object
      model.fit(
          x_train,
          y_train,
          batch_size=BATCH_SIZE,
          validation_data=(x_test, y_test),
          callbacks=cbks,
          epochs=2,
          verbose=0,
      )
  
      with open(filepath) as csvfile:
          list_lines = csvfile.readlines()
          for line in list_lines:
              assert line.count(sep) == 4
          assert len(list_lines) == 5
          output = " ".join(list_lines)
          assert len(re.findall("epoch", output)) == 1
  
      os.remove(filepath)
  
      # case 3, Verify Val. loss also registered when Validation Freq > 1
      model = make_model()
      cbks = [callbacks.CSVLogger(filepath, separator=sep)]
      hist = model.fit(
          x_train,
          y_train,
          batch_size=BATCH_SIZE,
          validation_data=(x_test, y_test),
          validation_freq=3,
          callbacks=cbks,
          epochs=5,
          verbose=0,
      )
      assert os.path.exists(filepath)
      # Verify that validation loss is registered at val. freq
      with open(filepath) as csvfile:
          rows = csv.DictReader(csvfile, delimiter=sep)
          for idx, row in enumerate(rows, 1):
              self.assertIn("val_loss", row)
              if idx == 3:
                  self.assertEqual(
                      row["val_loss"], str(hist.history["val_loss"][0])
                  )
              else:
                  self.assertEqual(row["val_loss"], "NA")
  
file_path: keras/keras/callbacks/csv_logger_test.py
imports: import csv
  import os
  import re
  import tempfile
  import numpy
  import pytest
  from keras import callbacks
  from keras import initializers
  from keras import layers
  from keras import testing
  from keras.models import Sequential
  from keras.utils import numerical_utils
label_desc: Use image node_id 1 for calling the CSVLoggerTest obj's underlying member method code with example usage: obj.test_CSVLogger() and returns: model