add tool to dump images in tensorboard event file
This commit is contained in:
parent
97ded53b30
commit
87cbcf34d3
41
tool/dump_tensorboard.py
Normal file
41
tool/dump_tensorboard.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import pathlib
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
from tensorboard.backend.event_processing import event_accumulator
|
||||||
|
|
||||||
|
|
||||||
|
# ffmpeg -framerate 1 -i ./tmp/test_b/%04d.jpg -vcodec mpeg4 test_b.mp4
|
||||||
|
# https://gist.github.com/hysts/81a0d30ac4f33dfa0c8859383aec42c2
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--path', type=str, required=True)
|
||||||
|
parser.add_argument('--outdir', type=str, required=True)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
event_acc = event_accumulator.EventAccumulator(
|
||||||
|
args.path, size_guidance={'images': 0})
|
||||||
|
event_acc.Reload()
|
||||||
|
|
||||||
|
outdir = pathlib.Path(args.outdir)
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Loading…
Reference in New Issue
Block a user