TensorBoard - Plot training and validation losses on the same graph?

前端 未结 8 1759
不思量自难忘°
不思量自难忘° 2020-12-02 18:34

Is there a way to plot both the training losses and validation losses on the same graph?

It\'s easy to have two separate scalar summaries for each of them i

8条回答
  •  -上瘾入骨i
    2020-12-02 18:51

    Please let me contribute with some code sample in the answer given by @Lifu Huang. First download the loger.py from here and then:

    from logger import Logger
    def train_model(parameters...):
        N_EPOCHS = 15
        # Set the logger
        train_logger = Logger('./summaries/train_logs')
        test_logger = Logger('./summaries/test_logs')
        for epoch in range(N_EPOCHS):
    
            # Code to get train_loss and test_loss
    
            # ============ TensorBoard logging ============#
            # Log the scalar values
            train_info = {
                'loss': train_loss,
            }
            test_info = {
                'loss': test_loss,
            }
    
            for tag, value in train_info.items():
                train_logger.scalar_summary(tag, value, step=epoch)
            for tag, value in test_info.items():
                test_logger.scalar_summary(tag, value, step=epoch)
    

    Finally you run tensorboard --logdir=summaries/ --port=6006and you get:

提交回复
热议问题