首页 > 代码库 > caffe中accuracy和loss用python从log日志里面获取
caffe中accuracy和loss用python从log日志里面获取
import reimport pylab as plimport numpy as npif __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对圆括号()前面要加上转移字符\,还有点号也要加上转意字符\
caffe中accuracy和loss用python从log日志里面获取
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。