caffe 画loss和accuracy

import os

import sys

import numpy as np

import matplotlib.pyplotas plt

import math

import re

import pylab

from pylab import figure, show,legend

frommpl_toolkits.axes_grid1 import host_subplot

 

# read the logfile

fp = open('log.txt', 'r')

 

train_iterations =[]

train_loss = []

test_iterations =[]

test_accuracy = []

 

for ln in fp:

  # get train_iterations and train_loss

  if'] Iteration 'in ln and'loss = 'in ln:

    arr = re.findall(r'ion \b\d+\b,',ln)

    train_iterations.append(int(arr[0].strip(',')[4:]))

    train_loss.append(float(ln.strip().split(' = ')[-1]))

  # get test_iteraitions

  if'] Iteration'in ln and'Testing net (#0)'in ln:

    arr = re.findall(r'ion \b\d+\b,',ln)

    test_iterations.append(int(arr[0].strip(',')[4:]))

  # get test_accuracy

  if'#2:'in ln and'loss/top-5'in ln:

   test_accuracy.append(float(ln.strip().split(' = ')[-1]))

 

fp.close()

 

host =host_subplot(111)

plt.subplots_adjust(right=0.8) # ajust theright boundary of the plot window

par1 = host.twinx()

# set labels

host.set_xlabel("iterations")

host.set_ylabel("logloss")

par1.set_ylabel("validationaccuracy")

 

# plot curves

p1, =host.plot(train_iterations, train_loss, label="training log loss")

p2, =par1.plot(test_iterations, test_accuracy, label="validation accuracy")

 

# set locationof the legend,

# 1->rightupcorner, 2->leftup corner, 3->leftdown corner

#4->rightdown corner, 5->rightmid ...

host.legend(loc=5)

 

# set labelcolor

host.axis["left"].label.set_color(p1.get_color())

par1.axis["right"].label.set_color(p2.get_color())

# set the rangeof x axis of host and y axis of par1

host.set_xlim([-1500, 160000])

par1.set_ylim([0., 1.05])

 

plt.draw()

plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值