Keras: how to output learning rate onto tensorboard

后端 未结 4 497
無奈伤痛
無奈伤痛 2021-02-05 10:29

I add a callback to decay learning rate:

 keras.callbacks.ReduceLROnPlateau(monitor=\'val_loss\', factor=0.5, patience=100, 
                                   v         


        
4条回答
  •  囚心锁ツ
    2021-02-05 11:03

    According to the author of Keras, the proper way is to subclass the TensorBoard callback:

    from keras import backend as K
    from keras.callbacks import TensorBoard
    
    class LRTensorBoard(TensorBoard):
        def __init__(self, log_dir, **kwargs):  # add other arguments to __init__ if you need
            super().__init__(log_dir=log_dir, **kwargs)
    
        def on_epoch_end(self, epoch, logs=None):
            logs = logs or {}
            logs.update({'lr': K.eval(self.model.optimizer.lr)})
            super().on_epoch_end(epoch, logs)
    

    Then pass it as part of the callbacks argument to model.fit (credit Finncent Price):

    model.fit(x=..., y=..., callbacks=[LRTensorBoard(log_dir="/tmp/tb_log")])
    

提交回复
热议问题