在熟悉了Caffe的基本历程之后,是时候利用实践来提高对其的掌握了,结合课题需要,选取了一些数据。首先选取了一小部分数据,在小数量集上测试神经网络的准确率是否能够收敛到100%,按照教程说法,神经网络这么强的学习能力在小数据集上都不能完全学习到,肯定就是神经网络搭建有问题。
数据类型
训练数据共五类,每类100组样本;测试样本分为两部分,一部分时与训练样本同源的数据集共五类,每类5组,一部分来源不同的信噪比较低的数据集,只有两类,每类3组。
网络选取
还是选择上次用到的LeNet网络,原因有两点:
1,在对其他网络结构不了解的基础上换来换去觉得没什么意思,在对模型及数据的了解基础之上再去选择合适数据的模型我觉得才是王道,而现在我这个新手只能拿什么用什么先试一试效果
2, LeNet感觉稍微简单一点模型,层数没那么多,毕竟现在只能用CPU跑
首先设置lenet_solver.prototxt,因为是小数据量,所以把迭代次数什么的调节的很低
# The train/test net protocol buffer definition
net: "examples/myexample/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 25 testing images.
test_iter: 5
# Carry out testing every 100 training iterations.
test_interval: 10
# The base learning rate, momentum and the weight decay of the network.
base_lr: 0.01
momentum: 0.9
weight_decay: 0.0008
# The learning rate policy
lr_policy: "inv"
gamma: 0.0001
power: 0.75
# Display every 10 iterations
display: 5
# The maximum number of iterations
max_iter: 50
# snapshot intemediate results
snapshot: 25
snapshot_prefix: "examples/myexample/lenet"
# solver mode: CPU or GPU
solver_mode: CPU
由训练过程可以看出,初始的识别率为20%,平均分类,loss=1.6
迭代到第五次时,loss=0.23
然后迭代到第十次时,测试集的准确率就已经收敛到100%,而loss=0.0021712
而训练的loss=0.0042255
随着迭代的增加,loss逐渐趋于0
结论:LeNet在小数据集上能快速的收敛到100%
然后将训练好的该模型用来预测第二部分的测试集
sudo ./build/tools/caffe.bin test \
-model examples/myexample/lenet_train_test.prototxt \
-weights examples/myexample/lenet_iter_50.caffemodel \
-iterations 10
结果可以看到,准确率只有可怜的50%
但是使用迭代了115次的模型来预测,准确率却有了83.3%
这个。。不是很懂额