caffe中accuracy和loss用python从log日志里面获取
import re import pylab as pl import numpy as np if __name__=="__main__": accuracys=[] losses=[] with open(r'/home/wxl/bnscallog.txt','r') as f: lines=f.readlines(); print 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}'; pattern2=r'Iteration \d+, loss = 0\.\d{6}'; accuracys=re.findall(pattern1,str); losses=re.findall(pattern2,str); print len(accuracys),'aaaa'; print 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() '''
注意:python对圆括号()前面要加上转移字符\,还有点号也要加上转意字符\