|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import shlex |
|
import sys |
|
from pathlib import Path |
|
import os |
|
|
|
os.environ['CUDA_VISIBLE_DEVICES'] = '' |
|
|
|
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' |
|
import tensorflow as tf |
|
from tensorflow.core.util.event_pb2 import Event |
|
|
|
def rename_events(input_file, old_tags, new_tag): |
|
new_file = input_file + ".new" |
|
|
|
with tf.io.TFRecordWriter(new_file) as writer: |
|
|
|
for rec in tf.data.TFRecordDataset([input_file]): |
|
|
|
ev = Event() |
|
ev.MergeFromString(rec.numpy()) |
|
|
|
|
|
if ev.summary: |
|
|
|
for v in ev.summary.value: |
|
|
|
|
|
if v.tag in old_tags: |
|
|
|
v.tag = new_tag |
|
writer.write(ev.SerializeToString()) |
|
os.rename(new_file, input_file) |
|
|
|
def rename_events_dir(input_file, old_tags, new_tag): |
|
|
|
rename_events(input_file, old_tags, new_tag) |
|
|
|
if __name__ == '__main__': |
|
if len(sys.argv) != 4: |
|
print(f'{sys.argv[0]} <input file> <old tags> <new tag>', |
|
file=sys.stderr) |
|
sys.exit(1) |
|
input_file, old_tags, new_tag = sys.argv[1:] |
|
print(input_file, shlex.quote(old_tags), shlex.quote(new_tag)) |
|
old_tags = old_tags.split(';') |
|
rename_events_dir(input_file, old_tags, new_tag) |
|
|