├── .gitignore ├── README.md ├── demo.pb └── dump.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | *.egg-info 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tensorboard-dumper 2 | requires: `pip install tensorboard` 3 | 4 | This tool dumps images in tensorboard. 5 | 6 | tested on python3 7 | 8 | `python dump.py` dumps the images in the file `events.out.tfevents.` which is generated by tensorboard-pytorch's demo.py 9 | 10 | You can find the `events.out.tfevents...` file in the `runs` folder in tensorboard-pytorch after running `python demo.py`. 11 | -------------------------------------------------------------------------------- /demo.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lanpa/tensorboard-dumper/57e505553eef0a27cd2e400793bc6397176a5c55/demo.pb -------------------------------------------------------------------------------- /dump.py: -------------------------------------------------------------------------------- 1 | import struct 2 | import tensorboard.compat.proto.event_pb2 as event_pb2 3 | import io 4 | import argparse 5 | 6 | 7 | def read(data): 8 | header = struct.unpack('Q', data[:8]) 9 | 10 | # crc_hdr = struct.unpack('I', data[:4]) 11 | 12 | event_str = data[12:12+int(header[0])] # 8+4 13 | data = data[12+int(header[0])+4:] 14 | return data, event_str 15 | 16 | # crc_ev = struct.unpack('>I', data[:4]) 17 | 18 | 19 | 20 | def save_img(encoded, step, save_gif): 21 | from PIL import Image 22 | img = Image.open(io.BytesIO(encoded)) 23 | if save_gif: 24 | images.append(img) 25 | else: 26 | img.save('img_{}.png'.format(step), format='png') 27 | 28 | 29 | parser = argparse.ArgumentParser(description='tensorboard-dumper') 30 | parser.add_argument('--gif', default=False, action='store_true', help='save result as gif') 31 | parser.add_argument('--input', default='demo.pb', help='saved tensorboard file to read from') 32 | parser.add_argument('--output', default='output.gif', help='output filename for gif export') 33 | parser.add_argument('--maxframe', default=100, help='limit the number of frames') 34 | parser.add_argument('--duration', default=100, help='show time for each frame (ms)') 35 | 36 | args = parser.parse_args() 37 | 38 | 39 | try: 40 | with open(args.input, 'rb') as f: 41 | data = f.read() 42 | except FileNotFoundError: 43 | print('input file not found') 44 | exit() 45 | 46 | images = [] 47 | 48 | while data and args.maxframe>0: 49 | args.maxframe = args.maxframe-1 50 | data, event_str = read(data) 51 | event = event_pb2.Event() 52 | 53 | event.ParseFromString(event_str) 54 | if event.HasField('summary'): 55 | for value in event.summary.value: 56 | if value.HasField('simple_value'): 57 | print(value.simple_value, value.tag, event.step) 58 | if value.HasField('image'): 59 | img = value.image 60 | save_img(img.encoded_image_string, event.step, save_gif=args.gif) 61 | print('img saved.') 62 | 63 | if args.gif: 64 | from PIL import Image 65 | im = images[0] 66 | im.save(args.output, save_all=True, append_images=images, duration=100, loop=0) # forever 67 | 68 | --------------------------------------------------------------------------------