学习笔记:Caffe上配置和运行MNIST

转自:http://www.cnblogs.com/yymn/p/4553671.html

MNIST,一个经典的手写数字库,包含60000个训练样本和10000个测试样本,图片大小28*28,在Caffe上配置的第一个案例
 
1首先,获取minist的数据包。 这个版本是四个数据包
cd $CAFFE_ROOT
./data/mnist/get_mnist.sh

 

  1. #!/usr/bin/env sh  
  2. # This scripts downloads the mnist data and unzips it.  
  3. DIR="$( cd "$(dirname "$0")" ; pwd -P )"  
  4. cd $DIR  
  5. echo "Downloading..."  
  6.   
  7. wget --no-check-certificate http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz  
  8. wget --no-check-certificate http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz  
  9. wget --no-check-certificate http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz  
  10. wget --no-check-certificate http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz  
  11.   
  12. echo "Unzipping..."  
  13.   
  14.   
  15. gunzip train-images-idx3-ubyte.gz  
  16. gunzip train-labels-idx1-ubyte.gz  
  17. gunzip t10k-images-idx3-ubyte.gz  
  18. gunzip t10k-labels-idx1-ubyte.gz  
  19.   
  20.   
  21. # Creation is split out because leveldb sometimes causes segfault  
  22. # and needs to be re-created.  
  23.   
  24. echo "Done."  



然后执行

./examples/mnist/create_mnist.sh

 

  1. Creating lmdb...  
  2. Done.  


在这一步做了什么工作呢?
create_mnist.sh是利用caffe-master/build/examples/mnist/的convert_mnist_data.bin工具,将mnist date转化为可用的lmdb格式的文件。并将新生成的2个文件mnist-train-lmdb 和 mnist-test-lmdb放于create_mnist.sh同目录下。

2 数据准备好了,那么接下来的工作就是训练了。

http://caffe.berkeleyvision.org/gathered/examples/mnist.html

给出来的例子是 

./examples/mnist/train_lenet.sh

这个脚本调用的工具如下:

  1. ./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt  



还有其他的示例,如:

./examples/mnist/train_mnist_autoencoder.sh
这个脚本调用的工具如下: 

  1. ./build/tools/caffe train \  
  2.   --solver=examples/mnist/mnist_autoencoder_solver.prototxt  

 

 

运行完结果如下:

生成四个文件

lenet_iter_10000.caffemodel         
lenet_iter_10000.solverstate      
lenet_iter_5000.caffemodel         
lenet_iter_5000.solverstate 

屏幕显示每次
.......................
I0126 17:32:32.171516 18290 solver.cpp:246] Iteration 10000, loss = 0.00453533
I0126 17:32:32.171550 18290 solver.cpp:264] Iteration 10000, Testing net (#0)
I0126 17:32:40.498195 18290 solver.cpp:315]     Test net output #0: accuracy = 0.9903
I0126 17:32:40.498236 18290 solver.cpp:315]     Test net output #1: loss = 0.0309918 (* 1 = 0.0309918 loss)
I0126 17:32:40.498245 18290 solver.cpp:251] Optimization Done.
I0126 17:32:40.498249 18290 caffe.cpp:121] Optimization Done.

 

首先讨论训练的网络模型:LeNet: the MNIST Classification Model   http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf
  
LeNet 模型之前在手写识别上就有非常好的表现。caffe 这里提供的是一个改进版的LeNet模型,其中的 sigmoid 被rectified linear units (ReLUs) 替换。
(标准的sigmoid输出不具备稀疏性,需要用一些惩罚因子来训练出一大堆接近0的冗余数据来,从而产生稀疏数据,例如L1、L1/L2或Student-t作惩罚因子。因此需要进行无监督的预训练。多层的神经网络如果用sigmoid或tanh激活函数也不做pre-training的话会因为 gradient vanishing problem 而会无法收敛。ReLU则这没有这个问题。ReLU是线性修正,公式为:g(x) = max(0, x),是purelin的折线版。它的作用是如果计算出的值小于0,就让它等于0,否则保持原来的值不变。这是一种简单粗暴地强制某些数据为0的方法,然而经实践证明,训练后的网络完全具备适度的稀疏性。而且训练后的可视化效果和传统方式预训练出的效果很相似,这也说明了ReLU具备引导适度稀疏的能力。 来自讨论 http://tieba.baidu.com/p/3061925556

LeNet的结构和CNN的结构是由相似之处的,是由两个 convolutional layer 和 pooling layer交错连接 ,然后两个fully connected layers结构组成。  具体可参见http://deeplearning.net/tutorial/lenet.html,此外DeepID 有个简单直观的结构图,可以辅助了解 http://blog.csdn.net/stdcoutzyx/article/details/42091205

定义MNIST网络和MNIST Solver:

从 ./examples/mnist/train_lenet.sh 脚本调用的指令我们就可以看到,solver是定义在了$CAFFE_ROOT/examples/mnist/lenet_solver.prototxt 中。

 

  1. # The train/test net protocol buffer definition  
  2. net: "examples/mnist/lenet_train_test.prototxt"        //网络协议具体定义  
  3. # test_iter specifies how many forward passes the test should carry out.  
  4. # In the case of MNIST, we have test batch size 100 and 100 test iterations,  
  5. # covering the full 10,000 testing images.  
  6. test_iter: 100                                         //test迭代次数 如果batch_size =100,则100张图一批,训练100次,则可以覆盖10000张图的需求  
  7. # Carry out testing every 500 training iterations.        
  8. test_interval: 500                                     //训练迭代500次,测试一次  
  9. # The base learning rate, momentum and the weight decay of the network. //网络参数:学习率,动量,权重的衰减  
  10. base_lr: 0.01  
  11. momentum: 0.9  
  12. weight_decay: 0.0005  
  13. # The learning rate policy                            //学习策略:有固定学习率和每步递减学习率  
  14. lr_policy: "inv"  
  15. gamma: 0.0001  
  16. power: 0.75  
  17. # Display every 100 iterations                        //每迭代100次显示一次   
  18. display: 100  
  19. # The maximum number of iterations                    //最大迭代次数  
  20. max_iter: 10000  
  21. # snapshot intermediate results                       // 每5000次迭代存储一次数据,路径前缀是<span style="font-family: Arial, Helvetica, sans-serif;">examples/mnist/lenet</span>  
  22. snapshot: 5000  
  23. snapshot_prefix: "examples/mnist/lenet"  
  1. solver_mode: CPU  



 

再看一下./examples/mnist/train_mnist_autoencoder.sh 调用的 mnist_autoencoder_solver.prototxt  的solver定义 

 

  1. net: "examples/mnist/mnist_autoencoder.prototxt"  
  2. test_state: { stage: 'test-on-train' }  
  3. test_iter: 500  
  4. test_state: { stage: 'test-on-test' }  
  5. test_iter: 100  
  6. test_interval: 500  
  7. test_compute_loss: true  
  8. base_lr: 0.01  
  9. lr_policy: "step"  
  10. gamma: 0.1  
  11. stepsize: 10000  
  12. display: 100  
  13. max_iter: 65000  
  14. weight_decay: 0.0005  
  15. snapshot: 10000  
  16. snapshot_prefix: "examples/mnist/mnist_autoencoder"  
  17. momentum: 0.9  
  18. # solver mode: CPU or GPU  
  19. solver_mode: GPU  



 

MNIST网络定义在 $CAFFE_ROOT/examples/mnist/lenet_train_test.prototxt.  solver的第二行已经注明

具体解释 可以参见http://caffe.berkeleyvision.org/gathered/examples/mnist.html




$CAFFE_ROOT/examples/mnist/lenet_train_test.prototx


  1. name: "LeNet"  
  2. layers {  
  3.   name: "mnist"  
  4.   type: DATA  
  5.   top: "data"  
  6.   top: "label"  
  7.   data_param {  
  8.     source: "examples/mnist/mnist_train_lmdb"  
  9.     backend: LMDB  
  10.     batch_size: 64  
  11.   }  
  12.   transform_param {  
  13.     scale: 0.00390625  
  14.   }  
  15.   include: { phase: TRAIN }  
  16. }  
  17. layers {  
  18.   name: "mnist"  
  19.   type: DATA  
  20.   top: "data"  
  21.   top: "label"  
  22.   data_param {  
  23.     source: "examples/mnist/mnist_test_lmdb"  
  24.    backend: LMDB  
  25.     batch_size: 100  
  26.   
  27.   }  
  28.   transform_param {  
  29.     scale: 0.00390625  
  30.   }  
  31.   include: { phase: TEST }  
  32. }  
  33.   
  34.   
  35. layers {  
  36.   name: "conv1"  
  37.   type: CONVOLUTION  
  38.   bottom: "data"  
  39.   top: "conv1"  
  40.   blobs_lr: 1  
  41.   blobs_lr: 2  
  42.   convolution_param {  
  43.     num_output: 20  
  44.     kernel_size: 5  
  45.     stride: 1  
  46.     weight_filler {  
  47.       type: "xavier"  
  48.     }  
  49.     bias_filler {  
  50.       type: "constant"  
  51.     }  
  52.   }  
  53. }  
  54. layers {  
  55.   name: "pool1"  
  56.   type: POOLING  
  57.   bottom: "conv1"  
  58.   top: "pool1"  
  59.   pooling_param {  
  60.     pool: MAX  
  61.     kernel_size: 2  
  62.     stride: 2  
  63.   }  
  64. }  
  65. layers {  
  66.   name: "conv2"  
  67.   type: CONVOLUTION  
  68.   bottom: "pool1"  
  69.   top: "conv2"  
  70.   blobs_lr: 1  
  71.   blobs_lr: 2  
  72.   convolution_param {  
  73.     num_output: 50  
  74.     kernel_size: 5  
  75.     stride: 1  
  76.     weight_filler {  
  77.       type: "xavier"  
  78.     }  
  79.     bias_filler {  
  80.       type: "constant"  
  81.     }  
  82.   }  
  83. }  
  84. layers {  
  85.   name: "pool2"  
  86.   type: POOLING  
  87.   bottom: "conv2"  
  88.   top: "pool2"  
  89.   pooling_param {  
  90.     pool: MAX  
  91.     kernel_size: 2  
  92.     stride: 2  
  93.   }  
  94. }  
  95. layers {  
  96.   name: "ip1"  
  97.   type: INNER_PRODUCT  
  98.   bottom: "pool2"  
  99.   top: "ip1"  
  100.   blobs_lr: 1  
  101.   blobs_lr: 2  
  102.   inner_product_param {  
  103.     num_output: 500  
  104.     weight_filler {  
  105.       type: "xavier"  
  106.     }  
  107.     bias_filler {  
  108.       type: "constant"  
  109.     }  
  110.  }  
  111. }  
  112. layers {  
  113.   name: "relu1"  
  114.   type: RELU  
  115.   bottom: "ip1"  
  116.   top: "ip1"  
  117. }  
  118. layers {  
  119.   name: "ip2"  
  120.   type: INNER_PRODUCT  
  121.   bottom: "ip1"  
  122.   top: "ip2"  
  123.   blobs_lr: 1  
  124.   blobs_lr: 2  
  125.   inner_product_param {  
  126.     num_output: 10  
  127.     weight_filler {  
  128.       type: "xavier"  
  129.     }  
  130.     bias_filler {  
  131.       type: "constant"  
  132.     }  
  133.   }  
  134. }  
  135. layers {  
  136.   name: "accuracy"  
  137.   type: ACCURACY  
  138.   bottom: "ip2"  
  139.   bottom: "label"  
  140.   top: "accuracy"  
  141.   include: { phase: TEST }  
  142. }  
  143. layers {  
  144.   name: "loss"  
  145.   type: SOFTMAX_LOSS  
  146.   bottom: "ip2"  
  147.   bottom: "label"  
  148.   top: "loss"  
  149. }  




而examples/mnist/mnist_autoencoder.prototxt 的网络定义则复杂许多:我们也可以看到,里面采用的是sigmoid 而不是 RELU

  1. name: "MNISTAutoencoder"  
  2. layers {  
  3.   top: "data"  
  4.   name: "data"  
  5.   type: DATA  
  6.   data_param {  
  7.     source: "examples/mnist/mnist_train_lmdb"  
  8.     backend: LMDB  
  9.     batch_size: 100  
  10.   }  
  11.   transform_param {  
  12.     scale: 0.0039215684  
  13.   }  
  14.   include: { phase: TRAIN }  
  15. }  
  16. layers {  
  17.   top: "data"  
  18.   name: "data"  
  19.   type: DATA  
  20.   data_param {  
  21.     source: "examples/mnist/mnist_train_lmdb"  
  22.     backend: LMDB  
  23.     batch_size: 100  
  24.     scale: 0.0039215684  
  25.   }  
  26.   include: {  
  27.     phase: TEST  
  28.     stage: 'test-on-train'  
  29.   }  
  30. }  
  31. layers {  
  32.   top: "data"  
  33.   name: "data"  
  34.   type: DATA  
  35.   data_param {  
  36.     source: "examples/mnist/mnist_test_lmdb"  
  37.     backend: LMDB  
  38.     batch_size: 100  
  39.   }  
  40.   transform_param {  
  41.     scale: 0.0039215684  
  42.   }  
  43.   include: {  
  44.     phase: TEST  
  45.     stage: 'test-on-test'  
  46.   }  
  47. }  
  48. layers {  
  49.   bottom: "data"  
  50.   top: "flatdata"  
  51.   name: "flatdata"  
  52.   type: FLATTEN  
  53. }  
  54. layers {  
  55.   bottom: "data"  
  56.   top: "encode1"  
  57.   name: "encode1"  
  58.   type: INNER_PRODUCT  
  59.   blobs_lr: 1  
  60.   blobs_lr: 1  
  61.   weight_decay: 1  
  62.   weight_decay: 0  
  63.   inner_product_param {  
  64.     num_output: 1000  
  65.    weight_filler {  
  66.       type: "gaussian"  
  67.       std: 1  
  68.       sparse: 15  
  69.     }  
  70.     bias_filler {  
  71.       type: "constant"  
  72.       value: 0  
  73.     }  
  74.   }  
  75. }  
  76. layers {  
  77.   bottom: "encode1"  
  78.   top: "encode1neuron"  
  79.   name: "encode1neuron"  
  80.   type: SIGMOID  
  81. }  
  82. layers {  
  83.   bottom: "encode1neuron"  
  84.   top: "encode2"  
  85.   name: "encode2"  
  86.   type: INNER_PRODUCT  
  87.   blobs_lr: 1  
  88.   blobs_lr: 1  
  89.   weight_decay: 1  
  90.   weight_decay: 0  
  91.   inner_product_param {  
  92.     num_output: 500  
  93.     weight_filler {  
  94.       type: "gaussian"  
  95.       std: 1  
  96.       sparse: 15  
  97.     }  
  98.     bias_filler {  
  99.       type: "constant"  
  100.       value: 0  
  101.     }  
  102.   }  
  103. }  
  104. layers {  
  105.   bottom: "encode2"  
  106.   top: "encode2neuron"  
  107.   name: "encode2neuron"  
  108.   type: SIGMOID  
  109. }  
  110. layers {  
  111.  bottom: "encode2neuron"  
  112.   top: "encode3"  
  113.   name: "encode3"  
  114.   type: INNER_PRODUCT  
  115.   blobs_lr: 1  
  116.   blobs_lr: 1  
  117.   weight_decay: 1  
  118.   weight_decay: 0  
  119.   inner_product_param {  
  120.     num_output: 250  
  121.     weight_filler {  
  122.       type: "gaussian"  
  123.       std: 1  
  124.       sparse: 15  
  125.     }  
  126.     bias_filler {  
  127.       type: "constant"  
  128.       value: 0  
  129.     }  
  130.   }  
  131. }  
  132. layers {  
  133.   bottom: "encode3"  
  134.   top: "encode3neuron"  
  135.   name: "encode3neuron"  
  136.   type: SIGMOID  
  137. }  
  138. layers {  
  139.   bottom: "encode3neuron"  
  140.   top: "encode4"  
  141.   name: "encode4"  
  142.   type: INNER_PRODUCT  
  143.   blobs_lr: 1  
  144.   blobs_lr: 1  
  145.   weight_decay: 1  
  146.   weight_decay: 0  
  147.   inner_product_param {  
  148.     num_output: 30  
  149.     weight_filler {  
  150.       type: "gaussian"  
  151.       std: 1  
  152.       sparse: 15  
  153.     }  
  154.     bias_filler {  
  155.       type: "constant"  
  156.       value: 0  
  157.     }  
  158.   }  
  159. }  
  160. layers {  
  161.   bottom: "encode4"  
  162.   top: "decode4"  
  163.   name: "decode4"  
  164.   type: INNER_PRODUCT  
  165.   blobs_lr: 1  
  166.   blobs_lr: 1  
  167.   weight_decay: 1  
  168.   weight_decay: 0  
  169.   inner_product_param {  
  170.     num_output: 250  
  171.     weight_filler {  
  172.       type: "gaussian"  
  173.       std: 1  
  174.       sparse: 15  
  175.     }  
  176.     bias_filler {  
  177.       type: "constant"  
  178.       value: 0  
  179.     }  
  180.   }  
  181. }  
  182. layers {  
  183.   bottom: "decode4"  
  184.   top: "decode4neuron"  
  185.   name: "decode4neuron"  
  186.   type: SIGMOID  
  187. }  
  188. layers {  
  189.   bottom: "decode4neuron"  
  190.   top: "decode3"  
  191.   name: "decode3"  
  192.   type: INNER_PRODUCT  
  193.   blobs_lr: 1  
  194.   blobs_lr: 1  
  195.   weight_decay: 1  
  196.   weight_decay: 0  
  197.   inner_product_param {  
  198.     num_output: 500  
  199.     weight_filler {  
  200.       type: "gaussian"  
  201.       std: 1  
  202.       sparse: 15  
  203.     }  
  204.     bias_filler {  
  205.       type: "constant"  
  206.       value: 0  
  207.     }  
  208.   }  
  209. }  
  210. layers {  
  211.   bottom: "decode3"  
  212.   top: "decode3neuron"  
  213.   name: "decode3neuron"  
  214.   type: SIGMOID  
  215. }  
  216. layers {  
  217.   bottom: "decode3neuron"  
  218.   top: "decode2"  
  219.   name: "decode2"  
  220.   type: INNER_PRODUCT  
  221.   blobs_lr: 1  
  222.   blobs_lr: 1  
  223.   weight_decay: 1  
  224.   weight_decay: 0  
  225.   inner_product_param {  
  226.    num_output: 1000  
  227.     weight_filler {  
  228.       type: "gaussian"  
  229.       std: 1  
  230.       sparse: 15  
  231.     }  
  232.     bias_filler {  
  233.       type: "constant"  
  234.       value: 0  
  235.     }  
  236.   }  
  237. }  
  238. layers {  
  239.   bottom: "decode2"  
  240.   top: "decode2neuron"  
  241.   name: "decode2neuron"  
  242.   type: SIGMOID  
  243. }  
  244. layers {  
  245.   bottom: "decode2neuron"  
  246.   top: "decode1"  
  247.   name: "decode1"  
  248.   type: INNER_PRODUCT  
  249.   blobs_lr: 1  
  250.   blobs_lr: 1  
  251.   weight_decay: 1  
  252.   weight_decay: 0  
  253.   inner_product_param {  
  254.     num_output: 784  
  255.     weight_filler {  
  256.       type: "gaussian"  
  257.       std: 1  
  258.       sparse: 15  
  259.     }  
  260.     bias_filler {  
  261.       type: "constant"  
  262.       value: 0  
  263.     }  
  264.   }  
  265. }  
  266. layers {  
  267.   bottom: "decode1"  
  268.   bottom: "flatdata"  
  269.   top: "cross_entropy_loss"  
  270.   name: "loss"  
  271.   type: SIGMOID_CROSS_ENTROPY_LOSS  
  272.   loss_weight: 1  
  273. }  
  274. layers {  
  275.   bottom: "decode1"  
  276.   top: "decode1neuron"  
  277.   name: "decode1neuron"  
  278.   type: SIGMOID  
  279. }  
  280. layers {  
  281.   bottom: "decode1neuron"  
  282.   bottom: "flatdata"  
  283.   top: "l2_error"  
  284.   name: "loss"  
  285.   type: EUCLIDEAN_LOSS  
  286.   loss_weight: 0  
  287. }  





 

当所有数据都训练好之后,接下来就是如何将模型应用到实际数据了:

./build/tools/caffe.bin test -model=examples/mnist/lenet_train_test.prototxt -weights=examples/mnist/lenet_iter_10000.caffemodel -gpu=0 

如果没有GPU则使用

./build/tools/caffe.bin test -model=examples/mnist/lenet_train_test.prototxt -weights=examples/mnist/lenet_iter_10000.caffemodel

 

test:表示对训练好的模型进行Testing,而不是training。其他参数包括train, time, device_query。

-model=XXX:指定模型prototxt文件,这是一个文本文件,详细描述了网络结构和数据集信息。

 

 

输出如下:

 

  1. I0303 18:26:31.961637 27313 caffe.cpp:138] Use CPU.  
  2. I0303 18:26:32.035434 27313 net.cpp:275] The NetState phase (1) differed from the phase (0) specified by a rule in layer mnist  
  3. I0303 18:26:32.035794 27313 net.cpp:39] Initializing net from parameters:   
  4. name: "LeNet"  
  5. layers {  
  6.   top: "data"  
  7.   top: "label"  
  8.   name: "mnist"  
  9.   type: DATA  
  10.   data_param {  
  11.     source: "examples/mnist/mnist_test_lmdb"  
  12.     batch_size: 100  
  13.     backend: LMDB  
  14.   }  
  15.   include {  
  16.     phase: TEST  
  17.   }  
  18.   transform_param {  
  19.     scale: 0.00390625  
  20.   }  
  21. }  
  22. layers {  
  23.   bottom: "data"  
  24.   top: "conv1"  
  25.   name: "conv1"  
  26.   type: CONVOLUTION  
  27.   blobs_lr: 1  
  28.   blobs_lr: 2  
  29.   convolution_param {  
  30.     num_output: 20  
  31.     kernel_size: 5  
  32.     stride: 1  
  33.     weight_filler {  
  34.       type: "xavier"  
  35.     }  
  36.     bias_filler {  
  37.       type: "constant"  
  38.     }  
  39.   }  
  40. }  
  41. layers {  
  42.   bottom: "conv1"  
  43.   top: "pool1"  
  44.   name: "pool1"  
  45.   type: POOLING  
  46.   pooling_param {  
  47.     pool: MAX  
  48.     kernel_size: 2  
  49.     stride: 2  
  50.   }  
  51. }  
  52. layers {  
  53.   bottom: "pool1"  
  54.   top: "conv2"  
  55.   name: "conv2"  
  56.   type: CONVOLUTION  
  57.   blobs_lr: 1  
  58.   blobs_lr: 2  
  59.   convolution_param {  
  60.     num_output: 50  
  61.     kernel_size: 5  
  62.     stride: 1  
  63.     weight_filler {  
  64.       type: "xavier"  
  65.     }  
  66.     bias_filler {  
  67.       type: "constant"  
  68.     }  
  69.   }  
  70. }  
  71. layers {  
  72.   bottom: "conv2"  
  73.   top: "pool2"  
  74.   name: "pool2"  
  75.   type: POOLING  
  76.   pooling_param {  
  77.     pool: MAX  
  78.     kernel_size: 2  
  79.     stride: 2  
  80.   }  
  81. }  
  82. layers {  
  83.   bottom: "pool2"  
  84.   top: "ip1"  
  85.   name: "ip1"  
  86.   type: INNER_PRODUCT  
  87.   blobs_lr: 1  
  88.   blobs_lr: 2  
  89.   inner_product_param {  
  90.     num_output: 500  
  91.     weight_filler {  
  92.       type: "xavier"  
  93.     }  
  94.     bias_filler {  
  95.       type: "constant"  
  96.     }  
  97.   }  
  98. }  
  99. layers {  
  100.   bottom: "ip1"  
  101.   top: "ip1"  
  102.   name: "relu1"  
  103.   type: RELU  
  104. }  
  105. layers {  
  106.   bottom: "ip1"  
  107.   top: "ip2"  
  108.   name: "ip2"  
  109.   type: INNER_PRODUCT  
  110.   blobs_lr: 1  
  111.   blobs_lr: 2  
  112.   inner_product_param {  
  113.     num_output: 10  
  114.     weight_filler {  
  115.       type: "xavier"  
  116.     }  
  117.     bias_filler {  
  118.       type: "constant"  
  119.     }  
  120.   }  
  121. }  
  122. layers {  
  123.   bottom: "ip2"  
  124.   bottom: "label"  
  125.   top: "accuracy"  
  126.   name: "accuracy"  
  127.   type: ACCURACY  
  128.   include {  
  129.     phase: TEST  
  130.   }  
  131. }  
  132. layers {  
  133.   bottom: "ip2"  
  134.   bottom: "label"  
  135.   top: "loss"  
  136.   name: "loss"  
  137.   type: SOFTMAX_LOSS  
  138. }  
  139. I0303 18:26:32.035923 27313 net.cpp:67] Creating Layer mnist  
  140. I0303 18:26:32.035931 27313 net.cpp:356] mnist -> data  
  141. I0303 18:26:32.035948 27313 net.cpp:356] mnist -> label  
  142. I0303 18:26:32.035955 27313 net.cpp:96] Setting up mnist  
  143. I0303 18:26:32.076159 27313 data_layer.cpp:68] Opening lmdb examples/mnist/mnist_test_lmdb  
  144. I0303 18:26:32.084071 27313 data_layer.cpp:128] output data size: 100,1,28,28  
  145. I0303 18:26:32.084214 27313 net.cpp:103] Top shape: 100 1 28 28 (78400)  
  146. I0303 18:26:32.084223 27313 net.cpp:103] Top shape: 100 1 1 1 (100)  
  147. I0303 18:26:32.084249 27313 net.cpp:67] Creating Layer label_mnist_1_split  
  148. I0303 18:26:32.084257 27313 net.cpp:394] label_mnist_1_split <- label  
  149. I0303 18:26:32.084269 27313 net.cpp:356] label_mnist_1_split -> label_mnist_1_split_0  
  150. I0303 18:26:32.084280 27313 net.cpp:356] label_mnist_1_split -> label_mnist_1_split_1  
  151. I0303 18:26:32.084286 27313 net.cpp:96] Setting up label_mnist_1_split  
  152. I0303 18:26:32.084292 27313 net.cpp:103] Top shape: 100 1 1 1 (100)  
  153. I0303 18:26:32.084297 27313 net.cpp:103] Top shape: 100 1 1 1 (100)  
  154. I0303 18:26:32.084306 27313 net.cpp:67] Creating Layer conv1  
  155. I0303 18:26:32.084311 27313 net.cpp:394] conv1 <- data  
  156. I0303 18:26:32.084317 27313 net.cpp:356] conv1 -> conv1  
  157. I0303 18:26:32.084326 27313 net.cpp:96] Setting up conv1  
  158. I0303 18:26:32.084775 27313 net.cpp:103] Top shape: 100 20 24 24 (1152000)  
  159. I0303 18:26:32.084791 27313 net.cpp:67] Creating Layer pool1  
  160. I0303 18:26:32.084796 27313 net.cpp:394] pool1 <- conv1  
  161. I0303 18:26:32.084803 27313 net.cpp:356] pool1 -> pool1  
  162. I0303 18:26:32.084810 27313 net.cpp:96] Setting up pool1  
  163. I0303 18:26:32.099537 27313 net.cpp:103] Top shape: 100 20 12 12 (288000)  
  164. I0303 18:26:32.099583 27313 net.cpp:67] Creating Layer conv2  
  165. I0303 18:26:32.099593 27313 net.cpp:394] conv2 <- pool1  
  166. I0303 18:26:32.099606 27313 net.cpp:356] conv2 -> conv2  
  167. I0303 18:26:32.099619 27313 net.cpp:96] Setting up conv2  
  168. I0303 18:26:32.099905 27313 net.cpp:103] Top shape: 100 50 8 8 (320000)  
  169. I0303 18:26:32.099925 27313 net.cpp:67] Creating Layer pool2  
  170. I0303 18:26:32.099947 27313 net.cpp:394] pool2 <- conv2  
  171. I0303 18:26:32.099959 27313 net.cpp:356] pool2 -> pool2  
  172. I0303 18:26:32.099970 27313 net.cpp:96] Setting up pool2  
  173. I0303 18:26:32.099979 27313 net.cpp:103] Top shape: 100 50 4 4 (80000)  
  174. I0303 18:26:32.099990 27313 net.cpp:67] Creating Layer ip1  
  175. I0303 18:26:32.099998 27313 net.cpp:394] ip1 <- pool2  
  176. I0303 18:26:32.100008 27313 net.cpp:356] ip1 -> ip1  
  177. I0303 18:26:32.100019 27313 net.cpp:96] Setting up ip1  
  178. I0303 18:26:32.104487 27313 net.cpp:103] Top shape: 100 500 1 1 (50000)  
  179. I0303 18:26:32.104518 27313 net.cpp:67] Creating Layer relu1  
  180. I0303 18:26:32.104527 27313 net.cpp:394] relu1 <- ip1  
  181. I0303 18:26:32.104538 27313 net.cpp:345] relu1 -> ip1 (in-place)  
  182. I0303 18:26:32.104549 27313 net.cpp:96] Setting up relu1  
  183. I0303 18:26:32.104558 27313 net.cpp:103] Top shape: 100 500 1 1 (50000)  
  184. I0303 18:26:32.104571 27313 net.cpp:67] Creating Layer ip2  
  185. I0303 18:26:32.104579 27313 net.cpp:394] ip2 <- ip1  
  186. I0303 18:26:32.104591 27313 net.cpp:356] ip2 -> ip2  
  187. I0303 18:26:32.104604 27313 net.cpp:96] Setting up ip2  
  188. I0303 18:26:32.104676 27313 net.cpp:103] Top shape: 100 10 1 1 (1000)  
  189. I0303 18:26:32.104691 27313 net.cpp:67] Creating Layer ip2_ip2_0_split  
  190. I0303 18:26:32.104701 27313 net.cpp:394] ip2_ip2_0_split <- ip2  
  191. I0303 18:26:32.104710 27313 net.cpp:356] ip2_ip2_0_split -> ip2_ip2_0_split_0  
  192. I0303 18:26:32.104722 27313 net.cpp:356] ip2_ip2_0_split -> ip2_ip2_0_split_1  
  193. I0303 18:26:32.104733 27313 net.cpp:96] Setting up ip2_ip2_0_split  
  194. I0303 18:26:32.104743 27313 net.cpp:103] Top shape: 100 10 1 1 (1000)  
  195. I0303 18:26:32.104751 27313 net.cpp:103] Top shape: 100 10 1 1 (1000)  
  196. I0303 18:26:32.104763 27313 net.cpp:67] Creating Layer accuracy  
  197. I0303 18:26:32.104770 27313 net.cpp:394] accuracy <- ip2_ip2_0_split_0  
  198. I0303 18:26:32.104779 27313 net.cpp:394] accuracy <- label_mnist_1_split_0  
  199. I0303 18:26:32.104790 27313 net.cpp:356] accuracy -> accuracy  
  200. I0303 18:26:32.104802 27313 net.cpp:96] Setting up accuracy  
  201. I0303 18:26:32.104811 27313 net.cpp:103] Top shape: 1 1 1 1 (1)  
  202. I0303 18:26:32.104822 27313 net.cpp:67] Creating Layer loss  
  203. I0303 18:26:32.104830 27313 net.cpp:394] loss <- ip2_ip2_0_split_1  
  204. I0303 18:26:32.104838 27313 net.cpp:394] loss <- label_mnist_1_split_1  
  205. I0303 18:26:32.104848 27313 net.cpp:356] loss -> loss  
  206. I0303 18:26:32.104857 27313 net.cpp:96] Setting up loss  
  207. I0303 18:26:32.104869 27313 net.cpp:103] Top shape: 1 1 1 1 (1)  
  208. I0303 18:26:32.104877 27313 net.cpp:109]     with loss weight 1  
  209. I0303 18:26:32.104909 27313 net.cpp:170] loss needs backward computation.  
  210. I0303 18:26:32.104918 27313 net.cpp:172] accuracy does not need backward computation.  
  211. I0303 18:26:32.104925 27313 net.cpp:170] ip2_ip2_0_split needs backward computation.  
  212. I0303 18:26:32.104933 27313 net.cpp:170] ip2 needs backward computation.  
  213. I0303 18:26:32.104941 27313 net.cpp:170] relu1 needs backward computation.  
  214. I0303 18:26:32.104948 27313 net.cpp:170] ip1 needs backward computation.  
  215. I0303 18:26:32.104956 27313 net.cpp:170] pool2 needs backward computation.  
  216. I0303 18:26:32.104964 27313 net.cpp:170] conv2 needs backward computation.  
  217. I0303 18:26:32.104975 27313 net.cpp:170] pool1 needs backward computation.  
  218. I0303 18:26:32.104984 27313 net.cpp:170] conv1 needs backward computation.  
  219. I0303 18:26:32.104991 27313 net.cpp:172] label_mnist_1_split does not need backward computation.  
  220. I0303 18:26:32.105000 27313 net.cpp:172] mnist does not need backward computation.  
  221. I0303 18:26:32.105006 27313 net.cpp:208] This network produces output accuracy  
  222. I0303 18:26:32.105017 27313 net.cpp:208] This network produces output loss  
  223. I0303 18:26:32.105034 27313 net.cpp:467] Collecting Learning Rate and Weight Decay.  
  224. I0303 18:26:32.105046 27313 net.cpp:219] Network initialization done.  
  225. I0303 18:26:32.105053 27313 net.cpp:220] Memory required for data: 8086808  
  226. I0303 18:26:32.136730 27313 caffe.cpp:145] Running for 50 iterations.  
  227. I0303 18:26:32.243196 27313 caffe.cpp:169] Batch 0, accuracy = 1  
  228. I0303 18:26:32.243229 27313 caffe.cpp:169] Batch 0, loss = 0.0140614  
  229. I0303 18:26:32.326557 27313 caffe.cpp:169] Batch 1, accuracy = 1  
  230. I0303 18:26:32.326588 27313 caffe.cpp:169] Batch 1, loss = 0.00749996  
  231. I0303 18:26:32.409931 27313 caffe.cpp:169] Batch 2, accuracy = 0.99  
  232. I0303 18:26:32.409963 27313 caffe.cpp:169] Batch 2, loss = 0.0106815  
  233. I0303 18:26:32.493257 27313 caffe.cpp:169] Batch 3, accuracy = 0.99  
  234. I0303 18:26:32.493288 27313 caffe.cpp:169] Batch 3, loss = 0.0528439  
  235. I0303 18:26:32.576733 27313 caffe.cpp:169] Batch 4, accuracy = 0.99  
  236. I0303 18:26:32.576761 27313 caffe.cpp:169] Batch 4, loss = 0.0632355  
  237. I0303 18:26:32.660257 27313 caffe.cpp:169] Batch 5, accuracy = 0.99  
  238. I0303 18:26:32.660289 27313 caffe.cpp:169] Batch 5, loss = 0.041726  
  239. I0303 18:26:32.743624 27313 caffe.cpp:169] Batch 6, accuracy = 0.97  
  240. I0303 18:26:32.743654 27313 caffe.cpp:169] Batch 6, loss = 0.0816639  
  241. I0303 18:26:32.827059 27313 caffe.cpp:169] Batch 7, accuracy = 0.99  
  242. I0303 18:26:32.827090 27313 caffe.cpp:169] Batch 7, loss = 0.0146397  
  243. I0303 18:26:32.910567 27313 caffe.cpp:169] Batch 8, accuracy = 1  
  244. I0303 18:26:32.910598 27313 caffe.cpp:169] Batch 8, loss = 0.00730312  
  245. I0303 18:26:32.993976 27313 caffe.cpp:169] Batch 9, accuracy = 0.99  
  246. I0303 18:26:32.994007 27313 caffe.cpp:169] Batch 9, loss = 0.0225503  
  247. I0303 18:26:33.077335 27313 caffe.cpp:169] Batch 10, accuracy = 0.98  
  248. I0303 18:26:33.077366 27313 caffe.cpp:169] Batch 10, loss = 0.0657359  
  249. I0303 18:26:33.160778 27313 caffe.cpp:169] Batch 11, accuracy = 0.98  
  250. I0303 18:26:33.160809 27313 caffe.cpp:169] Batch 11, loss = 0.0431129  
  251. I0303 18:26:33.244256 27313 caffe.cpp:169] Batch 12, accuracy = 0.96  
  252. I0303 18:26:33.244284 27313 caffe.cpp:169] Batch 12, loss = 0.132687  
  253. I0303 18:26:33.327652 27313 caffe.cpp:169] Batch 13, accuracy = 0.98  
  254. I0303 18:26:33.327684 27313 caffe.cpp:169] Batch 13, loss = 0.0907693  
  255. I0303 18:26:33.411123 27313 caffe.cpp:169] Batch 14, accuracy = 0.99  
  256. I0303 18:26:33.411151 27313 caffe.cpp:169] Batch 14, loss = 0.0150445  
  257. I0303 18:26:33.494606 27313 caffe.cpp:169] Batch 15, accuracy = 0.98  
  258. I0303 18:26:33.494635 27313 caffe.cpp:169] Batch 15, loss = 0.0465094  
  259. I0303 18:26:33.578012 27313 caffe.cpp:169] Batch 16, accuracy = 0.99  
  260. I0303 18:26:33.578042 27313 caffe.cpp:169] Batch 16, loss = 0.0343866  
  261. I0303 18:26:33.661423 27313 caffe.cpp:169] Batch 17, accuracy = 0.99  
  262. I0303 18:26:33.661454 27313 caffe.cpp:169] Batch 17, loss = 0.0277292  
  263. I0303 18:26:33.744851 27313 caffe.cpp:169] Batch 18, accuracy = 1  
  264. I0303 18:26:33.744882 27313 caffe.cpp:169] Batch 18, loss = 0.0146081  
  265. I0303 18:26:33.828307 27313 caffe.cpp:169] Batch 19, accuracy = 0.99  
  266. I0303 18:26:33.828338 27313 caffe.cpp:169] Batch 19, loss = 0.0457058  
  267. I0303 18:26:33.911772 27313 caffe.cpp:169] Batch 20, accuracy = 0.98  
  268. I0303 18:26:33.911800 27313 caffe.cpp:169] Batch 20, loss = 0.086042  
  269. I0303 18:26:33.995313 27313 caffe.cpp:169] Batch 21, accuracy = 0.98  
  270. I0303 18:26:33.995343 27313 caffe.cpp:169] Batch 21, loss = 0.0756276  
  271. I0303 18:26:34.078820 27313 caffe.cpp:169] Batch 22, accuracy = 0.99  
  272. I0303 18:26:34.078850 27313 caffe.cpp:169] Batch 22, loss = 0.0306264  
  273. I0303 18:26:34.162230 27313 caffe.cpp:169] Batch 23, accuracy = 0.98  
  274. I0303 18:26:34.162261 27313 caffe.cpp:169] Batch 23, loss = 0.0438904  
  275. I0303 18:26:34.245688 27313 caffe.cpp:169] Batch 24, accuracy = 0.98  
  276. I0303 18:26:34.245718 27313 caffe.cpp:169] Batch 24, loss = 0.0494635  
  277. I0303 18:26:34.329123 27313 caffe.cpp:169] Batch 25, accuracy = 0.99  
  278. I0303 18:26:34.329152 27313 caffe.cpp:169] Batch 25, loss = 0.0670097  
  279. I0303 18:26:34.412616 27313 caffe.cpp:169] Batch 26, accuracy = 0.99  
  280. I0303 18:26:34.412647 27313 caffe.cpp:169] Batch 26, loss = 0.117325  
  281. I0303 18:26:34.496093 27313 caffe.cpp:169] Batch 27, accuracy = 0.99  
  282. I0303 18:26:34.496122 27313 caffe.cpp:169] Batch 27, loss = 0.0199489  
  283. I0303 18:26:34.579558 27313 caffe.cpp:169] Batch 28, accuracy = 0.98  
  284. I0303 18:26:34.579587 27313 caffe.cpp:169] Batch 28, loss = 0.0489519  
  285. I0303 18:26:34.663027 27313 caffe.cpp:169] Batch 29, accuracy = 0.96  
  286. I0303 18:26:34.663051 27313 caffe.cpp:169] Batch 29, loss = 0.103231  
  287. I0303 18:26:34.746485 27313 caffe.cpp:169] Batch 30, accuracy = 1  
  288. I0303 18:26:34.746516 27313 caffe.cpp:169] Batch 30, loss = 0.0104769  
  289. I0303 18:26:34.829927 27313 caffe.cpp:169] Batch 31, accuracy = 1  
  290. I0303 18:26:34.829990 27313 caffe.cpp:169] Batch 31, loss = 0.00431556  
  291. I0303 18:26:34.913399 27313 caffe.cpp:169] Batch 32, accuracy = 0.98  
  292. I0303 18:26:34.913429 27313 caffe.cpp:169] Batch 32, loss = 0.027013  
  293. I0303 18:26:34.996893 27313 caffe.cpp:169] Batch 33, accuracy = 1  
  294. I0303 18:26:34.996923 27313 caffe.cpp:169] Batch 33, loss = 0.00294145  
  295. I0303 18:26:35.080307 27313 caffe.cpp:169] Batch 34, accuracy = 0.99  
  296. I0303 18:26:35.080338 27313 caffe.cpp:169] Batch 34, loss = 0.0528829  
  297. I0303 18:26:35.163833 27313 caffe.cpp:169] Batch 35, accuracy = 0.93  
  298. I0303 18:26:35.163862 27313 caffe.cpp:169] Batch 35, loss = 0.164353  
  299. I0303 18:26:35.247449 27313 caffe.cpp:169] Batch 36, accuracy = 1  
  300. I0303 18:26:35.247481 27313 caffe.cpp:169] Batch 36, loss = 0.00703398  
  301. I0303 18:26:35.331092 27313 caffe.cpp:169] Batch 37, accuracy = 0.97  
  302. I0303 18:26:35.331121 27313 caffe.cpp:169] Batch 37, loss = 0.0861889  
  303. I0303 18:26:35.414821 27313 caffe.cpp:169] Batch 38, accuracy = 0.99  
  304. I0303 18:26:35.414850 27313 caffe.cpp:169] Batch 38, loss = 0.028661  
  305. I0303 18:26:35.498474 27313 caffe.cpp:169] Batch 39, accuracy = 0.99  
  306. I0303 18:26:35.498502 27313 caffe.cpp:169] Batch 39, loss = 0.0414709  
  307. I0303 18:26:35.582015 27313 caffe.cpp:169] Batch 40, accuracy = 1  
  308. I0303 18:26:35.582042 27313 caffe.cpp:169] Batch 40, loss = 0.0357227  
  309. I0303 18:26:35.665555 27313 caffe.cpp:169] Batch 41, accuracy = 0.99  
  310. I0303 18:26:35.665585 27313 caffe.cpp:169] Batch 41, loss = 0.0525798  
  311. I0303 18:26:35.749254 27313 caffe.cpp:169] Batch 42, accuracy = 1  
  312. I0303 18:26:35.749285 27313 caffe.cpp:169] Batch 42, loss = 0.0257062  
  313. I0303 18:26:35.833019 27313 caffe.cpp:169] Batch 43, accuracy = 0.99  
  314. I0303 18:26:35.833048 27313 caffe.cpp:169] Batch 43, loss = 0.0198026  
  315. I0303 18:26:35.916801 27313 caffe.cpp:169] Batch 44, accuracy = 1  
  316. I0303 18:26:35.916833 27313 caffe.cpp:169] Batch 44, loss = 0.0178475  
  317. I0303 18:26:36.000491 27313 caffe.cpp:169] Batch 45, accuracy = 0.97  
  318. I0303 18:26:36.000522 27313 caffe.cpp:169] Batch 45, loss = 0.0608676  
  319. I0303 18:26:36.085665 27313 caffe.cpp:169] Batch 46, accuracy = 1  
  320. I0303 18:26:36.085697 27313 caffe.cpp:169] Batch 46, loss = 0.0100693  
  321. I0303 18:26:36.169760 27313 caffe.cpp:169] Batch 47, accuracy = 0.98  
  322. I0303 18:26:36.169791 27313 caffe.cpp:169] Batch 47, loss = 0.0211241  
  323. I0303 18:26:36.277791 27313 caffe.cpp:169] Batch 48, accuracy = 0.95  
  324. I0303 18:26:36.277822 27313 caffe.cpp:169] Batch 48, loss = 0.111764  
  325. I0303 18:26:36.361287 27313 caffe.cpp:169] Batch 49, accuracy = 1  
  326. I0303 18:26:36.361318 27313 caffe.cpp:169] Batch 49, loss = 0.0052372  
  327. I0303 18:26:36.361326 27313 caffe.cpp:174] Loss: 0.0452134  
  328. I0303 18:26:36.361332 27313 caffe.cpp:186] accuracy = 0.986  
  329. I0303 18:26:36.361341 27313 caffe.cpp:186] loss = 0.0452134 (* 1 = 0.0452134 loss)  
  330. [root@localhost caffe]#   



 


参考文献:

学习笔记4 学习搭建自己的网络——MNIST在caffe上进行训练与学习-薛开宇
http://wenku.baidu.com/link?url=_sERcBsTCgKElwFi7Hf9FXFe3J-c35ftm27Trf8SJX_iGsR2SlKDDIJmF-5DYruWK-uYJu5pYA3MMfcYt_IRiTL95tYVZ72TYwVTxf0JF27
Deep Learning(深度学习)学习笔记整理系列之LeNet-5卷积参数个人理解 :http://blog.csdn.net/qiaofangjie/article/details/16826849
Deep Learning论文笔记之(四)CNN卷积神经网络推导和实现:http://blog.csdn.net/zouxy09/article/details/9993371
Deep Learning论文笔记之(六)Multi-Stage多级架构分析:http://blog.csdn.net/zouxy09/article/details/10007237
cuda-convnet 卷积神经网络 一般性结构卷积核个数 和 输入输出的关系以及输入输出的个数的说明: http://blog.csdn.net/zhubenfulovepoem/article/details/29583429
DeepID http://blog.csdn.net/stdcoutzyx/article/details/42091205

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值