5 import matplotlib.pyplot
as plt
11 parser = argparse.ArgumentParser()
12 parser.add_argument(
'--input', type=str, required=
True)
13 parser.add_argument(
'--output', type=str, required=
True)
14 args = parser.parse_args()
18 lossPattern =
r"Iteration (?P<iter_num>\d+) .*, loss = (?P<loss_val>[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?)" 23 for pair
in re.findall(lossPattern,
open(logPath,
'r').read()): 24 iterations.append(int(pair[0])) 25 losses.append(float(pair[1])) 27 return pd.DataFrame({
"iteration":iterations,
"loss":losses})
33 df.plot(
"iteration",
"loss")
36 iterationPattern =
r"Iteration (?P<iter_num>\d+), Testing net" 37 iterations = [
int(r)
for r
38 in re.findall(iterationPattern,
39 open(logPath,
'r').read())] 41 testPattern = r"Test net output #0: loss3/loss3 = (?P<loss_val>[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?)" 42 tests = [
float(r[0])
for r
43 in re.findall(testPattern,
open(logPath,
'r').read())] 45 accPattern = r" Test net output #1: loss3/top-1 = (?P<loss_val>[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?)" 46 accs = [
float(r[0])
for r
47 in re.findall(accPattern,
open(logPath,
'r').read())] 48 print len(iterations), len(tests), len(accs)
50 return pd.DataFrame({
"iteration":iterations,
"loss":tests,
"accuracy":accs})
52 TGaxis.SetMaxDigits(8)
58 ax = df.plot(
"iteration",
"loss", label=
"Train Loss")
59 tdf.plot(
"iteration",
"loss", ax=ax, label=
"Test Loss" )
61 df[
"rollavg"] = pd.rolling_window(df.loss, window=200, win_type=
"boxcar")
63 ax = df.plot(
"iteration",
"rollavg", label=
"Train Loss")
64 tdf.plot(
"iteration",
"loss", ax=ax, label=
"Test Loss" )
66 tdf.plot(
"iteration",
"accuracy", label=
"Test Accuracy" )
68 tdf[
"rollacc"] = pd.rolling_window(tdf.accuracy, window=10, win_type=
"boxcar")
69 ax = tdf.plot(
"iteration",
"rollacc", label=
"Test Accuracy" )
72 trainLoss.SetName(
"trainLoss")
75 testLoss.SetName(
"testLoss")
77 testAccuracy = TGraph()
78 testAccuracy.SetName(
"testAccuracy")
80 trainLoss.SetLineColor(kGreen+2);
81 testLoss.SetLineColor(kBlue);
82 testAccuracy.SetLineColor(kRed);
84 trainLoss.SetLineWidth(2);
85 testLoss.SetLineWidth(2);
86 testAccuracy.SetLineWidth(2);
89 for num, row
in tdf.iterrows():
90 testLoss.SetPoint(iPoint, row.iteration, row.loss)
91 testAccuracy.SetPoint(iPoint, row.iteration, row.accuracy)
95 for num, row
in df.iterrows():
96 if not np.isnan(row.rollavg):
97 trainLoss.SetPoint(iPoint, row.iteration, row.rollavg)
100 c1 = TCanvas(
"c1",
"gerrors2")
101 pad = TPad(
"pad",
"",0,0,1,1)
102 pad.SetFillColor(kWhite)
108 hr = c1.DrawFrame(0,2.0,2000000,4.0)
110 hr.SetXTitle(
"Number of Training Iterations")
111 hr.GetXaxis().CenterTitle()
112 hr.GetYaxis().SetTitleSize(.04)
113 hr.GetYaxis().CenterTitle()
114 hr.GetXaxis().SetTitleOffset(1.3)
115 hr.GetYaxis().SetTitleOffset(1.2)
116 hr.GetXaxis().SetNoExponent(kFALSE)
117 hr.GetXaxis().SetNdivisions(5)
118 hr.GetXaxis().SetLabelOffset(.02)
119 hr.SetFillColor(kWhite)
125 trainLoss.Draw(
"l same")
128 overlay = TPad(
"overlay",
"",0,0,1,1)
129 overlay.SetFillStyle(4000)
130 overlay.SetFillColor(kWhite)
131 overlay.SetFrameFillStyle(4000)
132 overlay.SetTickx(
False)
133 overlay.SetTicky(
False)
137 xmin = pad.GetUxmin()
139 xmax = pad.GetUxmax()
141 hframe = overlay.DrawFrame(xmin,ymin,xmax,ymax)
142 hframe.SetFillColor(kWhite)
143 hframe.GetXaxis().SetLabelOffset(99)
144 hframe.GetYaxis().SetLabelOffset(99)
145 hframe.GetXaxis().SetTickLength(0)
146 hframe.GetYaxis().SetTickLength(0)
148 testAccuracy.Draw(
"l")
150 mylegend = TLegend(0.63,0.67,0.86,0.89)
151 mylegend.AddEntry(trainLoss,
"Training Loss",
"L")
152 mylegend.AddEntry(testLoss,
"Test Loss",
"L")
153 mylegend.AddEntry(testAccuracy,
"Test Accuracy",
"L")
154 mylegend.SetLineWidth(0)
155 mylegend.SetBorderSize(0)
156 mylegend.SetFillStyle(0)
159 axis = TGaxis(xmax,ymin,xmax, ymax,ymin,ymax,510,
"+L")
160 axis.SetLineColor(kBlack)
161 axis.SetTitle(
"Accuracy")
162 axis.SetTitleFont(42)
163 axis.SetTitleOffset(1.1)
164 axis.SetTitleColor(kBlack)
165 axis.SetLabelFont(42)
167 axis.SetLabelColor(kBlack)
168 axis.SetLabelSize(.035)
175 outName =
"learning_" +
str(args.output) +
".png" bin1_2sigma SetFillColor(3)
def extractTestLoss(logPath)
procfile open("FD_BRL_v0.txt")
def extractTrainLoss(logPath)