Can I export a tensorflow summary to CSV?

后端 未结 4 817
太阳男子
太阳男子 2020-12-14 18:07

Is there a way to extract scalar summaries to CSV (preferably from within tensorboard) from tfevents files?

Example code

The following code generates tfeve

4条回答
  •  无人及你
    2020-12-14 18:16

    Here is my solution which bases on the previous solutions but can scale up.

    import os
    import numpy as np
    import pandas as pd
    
    from collections import defaultdict
    from tensorboard.backend.event_processing.event_accumulator import EventAccumulator
    
    
    def tabulate_events(dpath):
    
        final_out = {}
        for dname in os.listdir(dpath):
            print(f"Converting run {dname}",end="")
            ea = EventAccumulator(os.path.join(dpath, dname)).Reload()
            tags = ea.Tags()['scalars']
    
            out = {}
    
            for tag in tags:
                tag_values=[]
                wall_time=[]
                steps=[]
    
                for event in ea.Scalars(tag):
                    tag_values.append(event.value)
                    wall_time.append(event.wall_time)
                    steps.append(event.step)
    
                out[tag]=pd.DataFrame(data=dict(zip(steps,np.array([tag_values,wall_time]).transpose())), columns=steps,index=['value','wall_time'])
    
            if len(tags)>0:      
                df= pd.concat(out.values(),keys=out.keys())
                df.to_csv(f'{dname}.csv')
                print("- Done")
            else:
                print('- Not scalers to write')
    
            final_out[dname] = df
    
    
        return final_out
    if __name__ == '__main__':
        path = "youre/path/here"
        steps = tabulate_events(path)
        pd.concat(steps.values(),keys=steps.keys()).to_csv('all_result.csv')
    

提交回复
热议问题