In this blog, we will discuss Keras CSVLogger callback. As clear from the name, this streams the training events like ‘loss’, ‘acc’ etc. to a csv file. Using this you can export all the values that can be represented as a string. So, let’s discuss its Keras API.
1 |
keras.callbacks.CSVLogger(filename, separator=',', append=False) |
Here, the “filename” is the name of the csv file where you want to keep the record. This also gives you an option of how to separate elements in the csv file. You can pass this as a string in the “separator” argument.
This also provides an option of whether to append the training history in an existing file or overwrite the existing file. For instance, if “append=False”, this will overwrite an existing file. Otherwise, it will append the information in the existing file without affecting the previously stored information in that file.
If no existing file is present this will create a new file and then append the information. Now, let’s see how to use this class.
1 2 3 4 5 6 7 8 9 |
# Load data, preprocessing and build model ... # First, create an instance of this CSVLogger class from keras.callbacks import CSVLogger call = CSVLogger('D:/train.csv', separator=',', append=False) #Then pass this as a list in the fit() method record = model.fit(..., callbacks=[call],...) |
That’s all for this blog. Hope you enjoy reading.
If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.