Tensorboardx: Is it possible to write all data to one single events.out.tfevents for one single run?

Created on 31 Jul 2019  路  3Comments  路  Source: lanpa/tensorboardX

According to my tests, if we use operations like add_hparams, add_scalars in tensorboardX, tensorboardX will create separate events.out.tfevents file to hold those data, whereas some other operations like add_scalar, add_graph, etc. do not have this problem, they all write to the same events.out.tfevents file.

In all my tests, I have initialized and used a single instance of SummaryWriter, all operations are done with respect to the same SummaryWriter instance.

If different types of data are written into different events.out.tfevents files, in tensorboard they will also be represented by different colors. This will quickly run out of distinguishable colors.

So I would like to know if it is possible to write all data to one single events.out.tfevents for each single run to ensure that every run will be represented by the same color in tensorboard?

Most helpful comment

You can create your own function to write it to your existing SummaryWriter.
Having a look at the add_hparams method in tensorboardX\writer.py, a new SummaryWriter is used that creates the new log file:

exp, ssi, sei = hparams(hparam_dict, metric_dict)                                    

if not name:                                                                         
    name = str(time.time())                                                          

with SummaryWriter(logdir=os.path.join(self.file_writer.get_logdir(), name)) as w_hp:
    w_hp.file_writer.add_summary(exp)                                                
    w_hp.file_writer.add_summary(ssi)                                                
    w_hp.file_writer.add_summary(sei)                                                
    for k, v in metric_dict.items():                                                 
        w_hp.add_scalar(k, v, global_step)                                           

So your own function could look like this:

from tensorboardX.summary import hparams    

def add_hparams(writer, param_dict, metrics_dict):              
    exp, ssi, sei = hparams(param_dict, metrics_dict)   
    writer.file_writer.add_summary(exp)                 
    writer.file_writer.add_summary(ssi)                 
    writer.file_writer.add_summary(sei)                 
    for k, v in metrics_dict.items():                   
        writer.add_scalar(k, v)                         

NOTE: I experienced some strange problems and I think that is the reason, why a new event file is created here.
In some cases, hyperparameters and metrics are not displayed in the tensorboard hparams panel. I found out that this was always the case, when the tensorboard log_dir directly points to the folder where the event file is located, e.g. path/to/event/file. Hparams were displayed correctly, when log_dir points to a higher level directory, e.g. path/to/event.

Further note that I am not using symbolic folder trees to compare multiple event files as officially recommended. Instead I am using the log_dir_spec argument to define multiple log directories.

All 3 comments

The same here. It looks terrible indeed.

Did anyone find a solution for this?

You can create your own function to write it to your existing SummaryWriter.
Having a look at the add_hparams method in tensorboardX\writer.py, a new SummaryWriter is used that creates the new log file:

exp, ssi, sei = hparams(hparam_dict, metric_dict)                                    

if not name:                                                                         
    name = str(time.time())                                                          

with SummaryWriter(logdir=os.path.join(self.file_writer.get_logdir(), name)) as w_hp:
    w_hp.file_writer.add_summary(exp)                                                
    w_hp.file_writer.add_summary(ssi)                                                
    w_hp.file_writer.add_summary(sei)                                                
    for k, v in metric_dict.items():                                                 
        w_hp.add_scalar(k, v, global_step)                                           

So your own function could look like this:

from tensorboardX.summary import hparams    

def add_hparams(writer, param_dict, metrics_dict):              
    exp, ssi, sei = hparams(param_dict, metrics_dict)   
    writer.file_writer.add_summary(exp)                 
    writer.file_writer.add_summary(ssi)                 
    writer.file_writer.add_summary(sei)                 
    for k, v in metrics_dict.items():                   
        writer.add_scalar(k, v)                         

NOTE: I experienced some strange problems and I think that is the reason, why a new event file is created here.
In some cases, hyperparameters and metrics are not displayed in the tensorboard hparams panel. I found out that this was always the case, when the tensorboard log_dir directly points to the folder where the event file is located, e.g. path/to/event/file. Hparams were displayed correctly, when log_dir points to a higher level directory, e.g. path/to/event.

Further note that I am not using symbolic folder trees to compare multiple event files as officially recommended. Instead I am using the log_dir_spec argument to define multiple log directories.

Was this page helpful?
0 / 5 - 0 ratings