您的位置:首页 > 理论基础 > 计算机网络

【神经网络与深度学习】基于Windows+Caffe的Minst和CIFAR—10训练过程说明

2016-09-14 21:55 1406 查看


Minst训练

我的路径:G:\Caffe\Caffe For Windows\examples\mnist 

对于新手来说,初步完成环境的配置后,一脸茫然。不知如何跑Demo,有么有!那么接下来的教程就是我们这些新手的福利了。 
第一步:如果前面的train_net.cpp编译通过了,那么这个就非常简单。Caffe训练和测试的数据都是需要leveldb格式的,niuzhiheng大牛已经给我们转好了MNIST的数据格式。如下图: 



第二步:如上图所示,文件夹下有个get_mnist_leveldb.bat
,双击就可以下载到MNIS的leveldb文件。不能翻墙的,就到:http://download.csdn.net/detail/u012878523/8140305 下载吧。下载完 解压到…\examples\mnist 文件夹下。网络参数可以再lenet_train.prototxt中修改。GPU和CPU的切换在lenet_solver.prototxt中,打开后代码如下所示:
# The training protocol buffer definition
train_net: "lenet_train.prototxt"
# The testing protocol buffer definition
test_net: "lenet_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.01
momentum: 0.9
weight_decay: 0.0005
# The learning rate policy
lr_policy: "inv"
gamma: 0.0001
power: 0.75
# Display every 100 iterations
display: 100
# The maximum number of iterations
max_iter: 10000
# snapshot intermediate results
snapshot: 5000
snapshot_prefix: "lenet"
# solver mode: CPU or GPU
solver_mode: GPU    #两种方式二选一
#solver_mode: CPU


第三步:双击train_lenet。bat就可以训练该网络。每500轮进行一次测试。Tset Score 0是正确率。Test Score 1是测试损失函数值。上两张训练图: 





然后准确率的变化: 



损失函数值的变化: 



每迭代100次输出一次训练比率lr和训练损失函数值loss,模型的参数存储在lenet_iter_10000.solverstate中,然后这个模型就可以应用在新数据上了。

至此,minst的训练demo到此结束。然后试试cifar-10!


CIFAR-10 训练

第一步:数据库的说明:CIFAR-10 

60000张 32X32 彩色图像 10类 

50000张训练 

10000张测试 

附上一个的deeplearning的常用数据集下载链接,赶紧默默的收藏吧: 
http://deeplearning.net/datasets/ 


这是binary格式的,所以我们要把它转换成leveldb格式。

第二步:(部分直接复制别人的,因为没看到原作者是谁,所以就不上链接了。) 

/examples/cifar10文件夹中有一个 convert_cifar_data.cpp 

将他include到MainCaller.cpp中。如下: 



然后就编译,博主一次就通过了 ,在bin文件夹里出现convert_cifar_data.exe。 

接下来就可以进行格式转换。binary→leveldb。可以在bin文件夹下新建一个input文件夹。将cifar10.binary文件放在input文件夹中,这样转换时就不用写路径了。 

然后cmd进入bin文件夹,执行convert_cifar_data.exe后,在output文件夹下有cifar_train_leveldb和cifar_test_leveldb两个文件夹。里面是转化好的leveldb格式数据。

第三步:下面我们要求数据图像的均值编译../../tools/comput_image_mean.cpp 



编译成功后,没有出现comput_image_mean.exe。没关系,我们还有maincaller.exe,接下来求mean 

cmd进入bin,执行后,在bin文件夹下出现一个mean.binaryproto文件,这就是所需的均值文件。

第四步:训练cifar网络 

在…/examples/cifar10文件夹里已经有网络的配置文件,我们只需要将cifar_train_leveldb和cifar_test_leveldb两个文件夹还有mean.binaryproto文件拷到cifar0文件夹下。 
修改cifar10_quick_train.prototxt中的source: “cifar-train-leveldb” mean_file: “mean.binaryproto” 和cifar10_quick_test.prototxt中的source: “cifar-test-leveldb” mean_file: “mean.binaryproto”就可以了, 

后面再训练就类似于MNIST的训练。写一个train_quick.bat,内容如下: 

copy..//..//bin//MainCaller.exe..//..//bin//train_net.exeSETGLOG_logtostderr=1”../../bin/train_net.exe” cifar10_quick_solver.prototxt pause 

先编译一遍 train_net.cpp 

运行train_quick.bat,结果如下: 



备注: 

另外,更改cifar*solver.prototxt文件可以使用CPU训练, 

solver mode: GPU 

solver_mode: CPU 

可以看看CPU和GPU训练的差别。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐