机器学习-学习笔记 MNIST Fine-tuning(一)
来源:互联网 发布:淘宝花卉店铺推荐 编辑:程序博客网 时间:2024/05/16 03:45
Fine-tuning(Finetune|微调)
很多时候,我们的电脑跑不了那么多的数据,就可以去下载别人已经训练好的网络进行第二次训练,达到准确率更高,或者增加一个新的类别,让我们一步一步来。
在原有数据集上进行微调
我们之前训练好了mnist,我们可以修改lenet_solver.prototxt如下
# The train/test net protocol buffer definitionnet: "examples/mnist/lenet_train_test.prototxt"# test_iter specifies how many forward passes the test should carry out.# In the case of MNIST, we have test batch size 100 and 100 test iterations,# covering the full 10,000 testing images.test_iter: 10 # 测试时迭代几次# Carry out testing every 500 training iterations.test_interval: 500 # 每迭代多少次进行测试# The base learning rate, momentum and the weight decay of the network.base_lr: 0.001 #这里是学习速率,调小momentum: 0.9weight_decay: 0.0005# The learning rate policylr_policy: "inv"gamma: 0.0001power: 0.75# Display every 100 iterationsdisplay: 100# The maximum number of iterationsmax_iter: 2000 # 最大迭代次数# snapshot intermediate resultssnapshot: 5000 # 这是快照,即5000次迭代进行一次快照snapshot_prefix: "examples/mnist/lenet" # 快照前面的名字# solver mode: CPU or GPUsolver_mode: CPU
我们这里主要是将学习速率调低,使其更加精确,迭代次数减少(因为也不用那么多次了- -)。
sudo ./build/tools/caffe train --solver ./examples/mnist/lenet_solver.prototxt --weights ./examples/mnist/lenet_iter_10000.caffemodel
- 微调前
- 微调后
增加了0.1%- -,在试试看将学习策略改成step。
继续修改lenet_solver.prototxt文件如下
# The train/test net protocol buffer definitionnet: "examples/mnist/lenet_train_test.prototxt"# test_iter specifies how many forward passes the test should carry out.# In the case of MNIST, we have test batch size 100 and 100 test iterations,# covering the full 10,000 testing images.test_iter: 100# Carry out testing every 500 training iterations.test_interval: 500# The base learning rate, momentum and the weight decay of the network.base_lr: 0.001momentum: 0.9weight_decay: 0.0005# The learning rate policylr_policy: "step"gamma: 0.0001stepsize: 100# Display every 100 iterationsdisplay: 100# The maximum number of iterationsmax_iter: 2000# snapshot intermediate resultssnapshot: 5000snapshot_prefix: "examples/mnist/lenet"# solver mode: CPU or GPUsolver_mode: CPU
sudo ./build/tools/caffe.bin train -solver examples/mnist/lenet_solver.prototxt -weights examples/mnist/lenet_iter_2000.caffemodel
可以看到有进步了- -而且训练时间非常短。
我们试试看将数字0123456剔除,只训练789,接着用789的模型,训练0,看看能不能成功。
我们之前提取了mnist的图片,这次我们根据给出的标签,来进行分类。
首先需要创建文件夹
mkdir mnist_testmkdir ./mnist_test/0mkdir ./mnist_test/1mkdir ./mnist_test/2mkdir ./mnist_test/3mkdir ./mnist_test/4mkdir ./mnist_test/5mkdir ./mnist_test/6mkdir ./mnist_test/7mkdir ./mnist_test/8mkdir ./mnist_test/9
import numpy as npimport structimport matplotlib.pyplot as pyplotimport Imagedef unzip(fileName, labelName): binfile = open(fileName, 'rb') buf = binfile.read() binfileOfLabel = open(labelName, 'rb') bufOfLabel = binfileOfLabel.read() index = 0 index2 = 0 magic, numImages, numRows, numColumns = struct.unpack_from( '>IIII', buf, index) index += struct.calcsize('>IIII') index2 += struct.calcsize('>II') n = [0 for x in range(0, 10)]; for image in range(0, numImages): im = struct.unpack_from('>784B', buf, index) label = struct.unpack_from('>1B', bufOfLabel, index2) index += struct.calcsize('>784B') index2 += struct.calcsize('>1B') im = np.array(im, dtype='uint8') im = im.reshape(28, 28) im = Image.fromarray(im) im.save('mnist_test/%d/train_%s.bmp' % (label[0], n[label[0]]), 'bmp') n[label[0]] += 1unzip('./caffe/data/mnist/t10k-images-idx3-ubyte', './caffe/data/mnist/t10k-labels-idx1-ubyte')
好了,把数字分割开来以后,我们需要将要测试数据随机存入mdb
阅读全文
1 0
- 机器学习-学习笔记 MNIST Fine-tuning(一)
- 机器学习-学习笔记 MNIST Fine-tuning(二)
- 学习笔记: pycaffe example 之 fine-tuning
- Caffe fine-tuning 学习
- 深度学习fine-tuning
- 迁移学习和fine-tuning
- MNIST 机器学习入门 (一)
- 机器学习笔记-MNIST数据库
- 迁移学习与fine-tuning的区别
- CNN+caffe学习1:fine-tuning
- Fine-tuning 深度学习操作指南
- MNIST机器学习入门(一)
- 机器学习入门--MNIST(一)
- TensorFlow笔记1-mnist机器学习教程
- caffe学习笔记10 -- Fine-tuning a Pretrained Network for Style Recognitio
- caffe学习笔记10.1--Fine-tuning a Pretrained Network for Style Recognition(new)
- caffe学习笔记2:Fine-tuning一个类别识别的预处理的网
- MNIST机器学习入门
- 我的演讲——科技创新的困境与解决方案
- AngularJS商品新增订单批量发货删除排序全选反选日期过滤
- Android RecyclerView添加头部
- PCB库元件的一个多余的点导致PCB绿色报错
- JavaWeb学习心得之Http协议
- 机器学习-学习笔记 MNIST Fine-tuning(一)
- Linux中查看当前目录下所有子目录空间占用情况的命令 [plain] view plain copy du -shc *
- stylus调用mixin函数
- RecyclerView的多条目加载适配器
- GeekBand笔记-《C++面向对象高级编程(上)》 第二周
- HTML引用
- 二分查找
- Hu不变矩原理及opencv实现
- 支付宝Sofa框架简明笔记