caffe入门2:举个栗子之mnist数据集

来源:互联网 发布:win php7 mysql 编辑:程序博客网 时间:2024/06/02 13:16

一、下载数据集
在caffe根目录下进入 $Caffe_ROOT/data/mnist文件夹

vim get_mnist.sh 
   #!/usr/bin/env sh   # This scripts downloads the mnist data and unzips it.   DIR="$( cd "$(dirname "$0")" ; pwd -P )"   cd $DIR   echo "Downloading..."   wget --no-check-certificate http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz  wget --no-check-certificate http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz  wget --no-check-certificate http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz  wget --no-check-certificate http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz  echo "Unzipping..."  gunzip train-images-idx3-ubyte.gz  gunzip train-labels-idx1-ubyte.gz  gunzip t10k-images-idx3-ubyte.gz  gunzip t10k-labels-idx1-ubyte.gz  # Creation is split out because leveldb sometimes causes segfault  # and needs to be re-created.  echo "Done."

代码作用是下载数据集并在当前目录解压
执行

./get_mnist.sh

网速正常的话,很快就会下载完。可以看到$caffe_Root/data/mnist内下载完成的数据。
二、生成lmdb文件
在caffe根目录下执行 ./examples/mnist/create_mnist.sh成功在文件夹examples内生成LMDB数据。
三、训练
在caffe根目录下执行./examples/mnist/train_lenet.sh开始训练。可以看到随着迭代次数的增加,精度逐渐上升。迭代到10000,训练停止。
样本的准确率达到99%。
四、一点补充
迭代过程中的每次输出,lr(learning rate)是指学习率,loss对应准确率。
训练脚本中可修改最大迭代次数使得训练不会无休止的进行。

1 1
原创粉丝点击