vdl_logger.py 633 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from .base_logger import BaseLogger
from visualdl import LogWriter

class VDLLogger(BaseLogger):
    def __init__(self, save_dir):
        super().__init__(save_dir)
        self.vdl_writer = LogWriter(logdir=save_dir)

    def log_metrics(self, metrics, prefix=None, step=None):
        if not prefix:
            prefix = ""
        updated_metrics = {prefix + "/" + k: v for k, v in metrics.items()}

        for k, v in updated_metrics.items():
            self.vdl_writer.add_scalar(k, v, step)
16 17 18 19
    
    def log_model(self, is_best, prefix, metadata=None):
        pass
    
20 21
    def close(self):
        self.vdl_writer.close()