安装完caffe,跑一遍MNIST程序进行实践。
Caffe官方提供了一系列的example供用户学习。可参见Caffe/examples.
本次的MNIST-LENet参考官方教程,caffe.berkeleyvision.org/gathered/examples/mnist.html。
在提供的examples里,Caffe把数据放在 ./data 文件夹下,处理后的数据和模型文件等放在 ./examples 文件夹下。本次的MNIST数据集即在 ./data/mnist 下,对应的模型和配置文件在 ./examples/mnist 下.
准备数据集
先进入Caffe的根目录($CAFFE_ROOT):
cd ~/caffe-master
下载MNIST数据集:
# 运行get_mnist.sh脚本
./data/mnist/get_mnist.sh
我们可以看一下这个脚本干啥了(gedit 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..."
for fname in train-images-idx3-ubyte train-labels-idx1-ubyte t10k-images-idx3-ubyte t10k-labels-idx1-ubyte
do
if [ ! -e $fname ]; then
wget --no-check-certificate http://yann.lecun.com/exdb/mnist/${fname}.gz
gunzip ${fname}.gz
fi
done
可以看到该shell脚本从 http://yann.lecun.com/exdb/mnist/${fname}.gz 依次下载了train-images-idx3-ubyte , train-labels-idx1-ubyte , t10k-images-idx3-ubyte, t10k-labels-idx1-ubyte4个文件。
等待一段时间下载完毕后解压。
Caffe不直接接收这样的数据集,需要处理成lmdb:
使用create_mnist.sh脚本处理数据:
./examples/mnist/create_mnist.sh
我们也可以看看这个脚本干了啥:
#!/usr/bin/env sh
# This script converts the mnist data into lmdb/leveldb format,
# depending on the value assigned to $BACKEND.
set -e
EXAMPLE=examples/mnist
DATA=data/mnist
BUILD=build/examples/mnist
BACKEND="lmdb"
echo "Creating ${BACKEND}..."
rm -rf $EXAMPLE/mnist_train_${BACKEND}
rm -rf $EXAMPLE/mnist_test_${BACKEND}
$BUILD/convert_mnist_data.bin $DATA/train-images-idx3-ubyte \
$DATA/train-labels-idx1-ubyte $EXAMPLE/mnist_train_${BACKEND} --backend=${BACKEND}
$BUILD/convert_mnist_data.bin $DATA/t10k-images-idx3-ubyte \
$DATA/t10k-labels-idx1-ubyte $EXAMPLE/mnist_test_${BACKEND} --backend=${BACKEND}
echo "Done."
可以看到使用的是./build/examples/mnist/convert_mnist_data.bin
工具完成转换的,这里就不深入看了
到这里数据集算是准备好了,存储在./examples/mnist/
下. mnist_train_lmdb, and mnist_test_lmdb
.
LeNet模型
Caffe的模型文件是以.prototxt
结尾,Caffe提供的LeNet文件在./examples/mnist/lenet_train_test.prototxt
,我们可以打开看看:
数据输入层:
————————————————
版权声明:本文为CSDN博主「DFann」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011974639/article/details/78804299
————————————————
版权声明:本文为CSDN博主「DFann」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/u011974639/article/details/78804299