Tensorboard histograms to matplotlib

后端 未结 4 1991
野性不改
野性不改 2021-02-10 00:48

I would like to \"dump\" the tensorboard histograms and plot them via matplotlib. I would have more scientific paper appealing plots.

I managed to hack the way through t

4条回答
  •  深忆病人
    2021-02-10 01:34

    The best solution is loading all events and reconstructing all the histogram (as the answer of @khuesmann) but not using EventAccumulator but EventFileLoader. This will give you a histogram per wall time and step as the ones Tensorboard plots. It can be extended to return a list of actions by timestep and wall time.

    Don't forget to check which tag will you use.

    from tensorboard.backend.event_processing.event_file_loader import EventFileLoader
    # Just in case, PATH_OF_FILE is the path of the file, not the folder
    loader = EventFileLoader(PATH_Of_FILE)
    
    # Where to store values
    wtimes,steps,actions = [],[],[]
    for event in loader.Load():
        wtime   = event.wall_time
        step    = event.step
        if len(event.summary.value) > 0:
            summary = event.summary.value[0]
            if summary.tag == HISTOGRAM_TAG:
                wtimes += [wtime]*int(summary.histo.num)
                steps  += [step] *int(summary.histo.num)
    
                for num,val in zip(summary.histo.bucket,summary.histo.bucket_limit):
                    actions += [val] *int(num)
    

    bear in mind that tensorflow approximates the actions and treats the actions as continuous variables, so even if you have discrete actions (e.g. 0,1,3) you will end up actions as 0.2,0.4,0.9,1.4 ... in that case round the values will do it.

提交回复
热议问题