Import Reimport Pylab as Plimport numpy as Npif __name__== "__main__": accuracys=[] losses=[] with open (R '/home/wxl/b Nscallog.txt ', ' R ') as F:lines=f.readlines ();p rint len (lines) str= "". Join (lines) str=str.replace (' \ n ', ') Print Len ( STR) pattern1=r ' Iteration \d{4,5}, testing net \ (#0 \) \w\d{1,6} \d{2}:\d{2}:\d{2}\.\d{1,6} \d{1,6} solver\.cpp:\d{2,5}] Test NET output #0: accuracy = 0\.\d{6} ';p attern2=r ' iteration \d+, loss = 0\.\d{6} '; Accuracys=re.findall (PATTERN1,STR); l Osses=re.findall (pattern2,str);p rint len (accuracys), ' aaaa ';p rint len (losses), ' = = = ' Print Accuracys with open (R '/home /wxl/project/code/loss ', ' w+ ') as F1:for ac in Losses:f1.write (ac[10:15]) f1.write (') F1.write (ac[23:]); F1.write (' \ n ') );‘‘‘ With open (R '/home/wxl/project/code/loss ', ' R ') as F2:lines=f2.readlines (); X=[];y=[]for line in Lines:if "," in Line:line =line.replace (', ', '); Tmp=line.strip (' \ n '). Split (') x.append (int (tmp[0))) Y.append (float (tmp[-1])) Pl.plot (x, y) Pl.show () "
Note: Python must precede the parentheses () with the transfer character \, plus a bit number to add the transpose character \
Caffe accuracy and loss from the log log in Python