Caffe学习系列(19): 绘制loss和accuracy曲线
2016-04-06 19:47
537 查看
转载自:
Caffe学习系列(19): 绘制loss和accuracy曲线 - denny402 - 博客园
http://www.cnblogs.com/denny402/p/5110204.html
如同前几篇的可视化,这里采用的也是jupyter notebook来进行曲线绘制。
In [1]:
设置求解器,和c++/caffe一样,需要一个solver配置文件。
In [2]:
如果不需要绘制曲线,只需要训练出一个caffemodel, 直接调用solver.solve()就可以了。如果要绘制曲线,就需要把迭代过程中的值
保存下来,因此不能直接调用solver.solve(), 需要迭代。在迭代过程中,每迭代200次测试一次
In [5]:
绘制train过程中的loss曲线,和测试过程中的accuracy曲线。
In [6]:
Out[6]:
Caffe学习系列(19): 绘制loss和accuracy曲线 - denny402 - 博客园
http://www.cnblogs.com/denny402/p/5110204.html
如同前几篇的可视化,这里采用的也是jupyter notebook来进行曲线绘制。
In [1]:
#加载必要的库 import numpy as np import matplotlib.pyplot as plt %matplotlib inline import sys,os,caffe #设置当前目录 caffe_root = '/home/bnu/caffe/' sys.path.insert(0, caffe_root + 'python') os.chdir(caffe_root)
设置求解器,和c++/caffe一样,需要一个solver配置文件。
In [2]:
# set the solver prototxt caffe.set_device(0) caffe.set_mode_gpu() solver = caffe.SGDSolver('examples/cifar10/cifar10_quick_solver.prototxt')
如果不需要绘制曲线,只需要训练出一个caffemodel, 直接调用solver.solve()就可以了。如果要绘制曲线,就需要把迭代过程中的值
保存下来,因此不能直接调用solver.solve(), 需要迭代。在迭代过程中,每迭代200次测试一次
In [5]:
%%time niter =4000 test_interval = 200 train_loss = np.zeros(niter) test_acc = np.zeros(int(np.ceil(niter / test_interval))) # the main solver loop for it in range(niter): solver.step(1) # SGD by Caffe # store the train loss train_loss[it] = solver.net.blobs['loss'].data solver.test_nets[0].forward(start='conv1') if it % test_interval == 0: acc=solver.test_nets[0].blobs['accuracy'].data print 'Iteration', it, 'testing...','accuracy:',acc test_acc[it // test_interval] = acc
Iteration 0 testing... accuracy: 0.10000000149 Iteration 200 testing... accuracy: 0.419999986887 Iteration 400 testing... accuracy: 0.479999989271 Iteration 600 testing... accuracy: 0.540000021458 Iteration 800 testing... accuracy: 0.620000004768 Iteration 1000 testing... accuracy: 0.629999995232 Iteration 1200 testing... accuracy: 0.649999976158 Iteration 1400 testing... accuracy: 0.660000026226 Iteration 1600 testing... accuracy: 0.660000026226 Iteration 1800 testing... accuracy: 0.670000016689 Iteration 2000 testing... accuracy: 0.709999978542 Iteration 2200 testing... accuracy: 0.699999988079 Iteration 2400 testing... accuracy: 0.75 Iteration 2600 testing... accuracy: 0.740000009537 Iteration 2800 testing... accuracy: 0.769999980927 Iteration 3000 testing... accuracy: 0.75 Iteration 3200 testing... accuracy: 0.699999988079 Iteration 3400 testing... accuracy: 0.740000009537 Iteration 3600 testing... accuracy: 0.72000002861 Iteration 3800 testing... accuracy: 0.769999980927 CPU times: user 41.7 s, sys: 54.2 s, total: 1min 35s Wall time: 1min 18s
绘制train过程中的loss曲线,和测试过程中的accuracy曲线。
In [6]:
print test_acc _, ax1 = plt.subplots() ax2 = ax1.twinx() ax1.plot(np.arange(niter), train_loss) ax2.plot(test_interval * np.arange(len(test_acc)), test_acc, 'r') ax1.set_xlabel('iteration') ax1.set_ylabel('train loss') ax2.set_ylabel('test accuracy')
[ 0.1 0.41999999 0.47999999 0.54000002 0.62 0.63 0.64999998 0.66000003 0.66000003 0.67000002 0.70999998 0.69999999 0.75 0.74000001 0.76999998 0.75 0.69999999 0.74000001 0.72000003 0.76999998]
Out[6]:
<matplotlib.text.Text at 0x7fd1297bfcd0>
相关文章推荐
- BufferedInputStream的read方法原理
- html5 div 简单布局
- js模版引擎handlebars.js实用教程——目录
- JavaScript DOM对象和JQuery对象相互转换
- Comet4J简介
- hihoCoder[Offer收割]编程练习赛3题目解析
- RabbitMQ消息队列的小伙伴(八): ProtoBuf(Google Protocol Buffer)
- Google Web Designer(HTML5网页可视化设计)
- 文件上传_JSCH
- html5 列表
- 随机数的组合问题(JavaScript描述)
- ReactNative学习十二-React-Native-Viewpager
- Extjs6问题——grid不显示数据
- js库开发--参数传递及方法修改
- AngularJS之基础-5 路由(定义路由、使用路由)、自定义指令(Directive)
- CSS样式积累
- [程序猿入行必备]CSS样式之优先级
- html5 表格
- CSS溢出实现一个图片放大的效果
- VS2015 安装mvc4安装包以及vs2010 sp1后导致Razor语法失效代码不高亮(能正常运行)/视图页面无法智能提示(.cshtml)解决办法