Skip to content

Instantly share code, notes, and snippets.

@typhoonzero
Created September 12, 2018 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typhoonzero/1705ca6847bbe81ecccc10afb101c9ab to your computer and use it in GitHub Desktop.
Save typhoonzero/1705ca6847bbe81ecccc10afb101c9ab to your computer and use it in GitHub Desktop.
from __future__ import print_function
import random
from visualdl import LogWriter
logdir = "resnet50_v100"
def parse_logdata(logfile):
loss_ret = {}
acc1_ret = {}
acc5_ret = {}
with open(logfile, "r") as fn:
for line in fn.readlines():
if not (line.startswith("Pass") or line.startswith("Test")):
continue
sections = [s.strip() for s in line.strip().split(",")]
if sections[0].startswith("Total") or sections[0].startswith("read images"):
continue
if sections[1].startswith("Test"):
passid = int(sections[0].replace("Pass: ", ""))
continue
# acc1 = sections[1].replace("Test Accuracy: [", "")
# acc5 = sections[2].replace("]", "")
# dist_test_acc1[passid] = float(acc1)
# dist_test_acc5[passid] = float(acc5)
else:
passid = int(sections[0].replace("Pass ", ""))
loss = float(sections[2].replace("loss ", ""))
acc1 = float(sections[3].replace("accucacys: [", ""))
acc5 = float(sections[4].replace("]", ""))
if not passid in loss_ret:
loss_ret[passid] = []
if not passid in acc1_ret:
acc1_ret[passid] = []
if not passid in acc5_ret:
acc5_ret[passid] = []
loss_ret[passid].append(loss)
acc1_ret[passid].append(acc1)
acc5_ret[passid].append(acc5)
# cal avg
ret = [{}, {}, {}]
for idx, data in enumerate([loss_ret, acc1_ret, acc5_ret]):
for passid in data:
ret[idx][passid] = sum(data[passid]) / len(data[passid])
return ret
def write_vdldata(logfile, logger, name_prefix):
data = parse_logdata(logfile)
with logger.mode("%s-loss" % name_prefix):
s0 = logger.scalar("%s/loss" % logdir)
with logger.mode("%s-acc1" % name_prefix):
s1 = logger.scalar("%s/acc1" % logdir)
with logger.mode("%s-acc5" % name_prefix):
s2 = logger.scalar("%s/acc1" % logdir)
for k, v in data[0].iteritems():
s0.add_record(k, v)
for k, v in data[1].iteritems():
s1.add_record(k, v)
for k, v in data[2].iteritems():
s2.add_record(k, v)
def main():
logger = LogWriter(logdir, sync_cycle=10000)
write_vdldata("local_8GPU_0.1_48_piecewise.log", logger, "local")
write_vdldata("nccl2_32GPU_0.1_32_piecewise.log", logger, "nccl2")
write_vdldata("ps_32GPU_0.1_48_piecewise.log", logger, "ps1")
write_vdldata("ps_32GPU_0.4_48_piecewise.log", logger, "ps4")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment