training_plots.py
Go to the documentation of this file.
1 import os, sys
2 import re
3 import pandas as pd
4 import argparse
5 import matplotlib.pyplot as plt
6 import numpy as np
7 
8 parser = argparse.ArgumentParser()
9 parser.add_argument('--input', type=str, required=True)
10 parser.add_argument('--output', type=str, required=True)
11 args = parser.parse_args()
12 log1=args.input
13 
14 def extractTrainLoss(logPath):
15  lossPattern = r"Iteration (?P<iter_num>\d+) .*, loss = (?P<loss_val>[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?)"
16 
17  iterations = []
18  losses = []
19 
20  for pair in re.findall(lossPattern, open(logPath, 'r').read()):
21  iterations.append(int(pair[0]))
22  losses.append(float(pair[1]))
23 
24  return pd.DataFrame({"iteration":iterations, "loss":losses})
25 
26 df = extractTrainLoss(log1)
27 
28 print df.head()
29 
30 df.plot("iteration", "loss")
31 
32 def extractTestLoss(logPath):
33  iterationPattern = r"Iteration (?P<iter_num>\d+), Testing net"
34  iterations = [int(r) for r
35  in re.findall(iterationPattern,
36  open(logPath, 'r').read())]
37 
38  testPattern = r"Test net output #0: loss3/loss3 = (?P<loss_val>[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?)"
39  tests = [float(r[0]) for r
40  in re.findall(testPattern, open(logPath, 'r').read())]
41 
42  accPattern = r" Test net output #1: loss3/top-1 = (?P<loss_val>[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?)"
43  accs = [float(r[0]) for r
44  in re.findall(accPattern, open(logPath, 'r').read())]
45  print len(iterations), len(tests), len(accs)
46 
47  return pd.DataFrame({"iteration":iterations, "loss":tests, "accuracy":accs})
48 
49 tdf = extractTestLoss(log1)
50 
51 ax = df.plot("iteration", "loss", label="Train Loss")
52 tdf.plot("iteration", "loss", ax=ax, label="Test Loss" )
53 
54 df["rollavg"] = pd.rolling_window(df.loss, window=200, win_type="boxcar")
55 
56 ax = df.plot("iteration", "rollavg", label="Train Loss")
57 tdf.plot("iteration", "loss", ax=ax, label="Test Loss" )
58 
59 tdf.plot("iteration", "accuracy", label="Test Accuracy" )
60 
61 tdf["rollacc"] = pd.rolling_window(tdf.accuracy, window=10, win_type="boxcar")
62 ax = tdf.plot("iteration", "rollacc", label="Test Accuracy" )
63 
64 open("test_"+args.output+".txt", 'w').write("\n".join("%s %s %s" % (row.iteration,
65  row.loss,
66  row.accuracy)
67  for num, row in tdf.iterrows()))
68 
69 open("train_"+args.output+".txt", 'w').write("\n".join("%s %s" % (row.iteration, row.rollavg)
70  for num, row in df.iterrows()
71  if not np.isnan(row.rollavg) ))
write
Run ND cosmics.
def extractTestLoss(logPath)
def extractTrainLoss(logPath)
procfile open("FD_BRL_v0.txt")