Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ArthurDelannoyazerty/64b822cc259652d314caeb0e4c540e58 to your computer and use it in GitHub Desktop.
Save ArthurDelannoyazerty/64b822cc259652d314caeb0e4c540e58 to your computer and use it in GitHub Desktop.
Extract images from Tensorboard log
import pathlib
import numpy as np
import cv2
from tensorboard.backend.event_processing import event_accumulator
event_filepath = 'runs/Apr19_11-02-02_RNSCWL0127/events.out.tfevents.1713517322.RNSCWL0127.15332.0'
output_dir = 'images/img_train'
event_acc = event_accumulator.EventAccumulator(event_filepath, size_guidance={'images': 0})
event_acc.Reload()
outdir = pathlib.Path(output_dir)
outdir.mkdir(exist_ok=True, parents=True)
for tag in event_acc.Tags()['images']:
events = event_acc.Images(tag)
tag_name = tag.replace('/', '_')
dirpath = outdir / tag_name
dirpath.mkdir(exist_ok=True, parents=True)
for index, event in enumerate(events):
s = np.frombuffer(event.encoded_image_string, dtype=np.uint8)
image = cv2.imdecode(s, cv2.IMREAD_COLOR)
outpath = dirpath / '{:04}.jpg'.format(index)
cv2.imwrite(outpath.as_posix(), image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment