How can I create a TensorFlow Keras API callback that, for every epoch, will add the learning rate value to the csv file created by tf.keras.callbacks.CSVLogger?
With the callback below I can print out my learning rate after each epoch, and add it to the history. But I can't figure out how to have it added to the CSVLogger csv file. It seems there is a log dict stored somewhere, which holds the values printed by CSVLogger, but I don't understand where it is or how to add to it.
class Print_lr(tf.keras.callbacks.Callback):
def on_epoch_begin(self, epoch, logs=None):
print('lr = %f' % self.model.optimizer.lr)
if 'lr' not in self.model.history.history.keys():
self.model.history.history['lr'] = []
self.model.history.history['lr'].append(self.model.optimizer.lr.numpy())