在mnist数据集中进行测试
安装好了caffe后,就开始在mnist数据集中测试一下吧。
进入/caffe/examples/mnist路径
分别修改lenet_solver.prototxt和lenet_train_test.prototxt文件中关于路径的部分
lenet_solver.prototxt
# The train/test net protocol buffer definition
net: "C:/Documents/Caffe/caffe/examples/mnist/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 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: "C:/Documents/Caffe/caffe/examples/mnist/lenet"
# solver mode: CPU or GPU
solver_mode: GPU
lenet_train_test.prototxt
name: "LeNet"
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
scale: 0.00390625
}
data_param {
source: "C:/Documents/Caffe/caffe/examples/mnist/mnist_train_lmdb"
batch_size: 64
backend: LMDB
}
}
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
}
data_param {
source: "C:/Documents/Caffe/caffe/examples/mnist/mnist_test_lmdb"
batch_size: 100
backend: LMDB
}
}
进入/caffe/data/mnist路径,打开get_mnist.sh下载数据集,Windows不能直接执行该文件,右键编辑打开文件,进入其中的网页,手动下载数据集。
然后将解压缩后的文件转换成IMDB格式即可。
将解压缩后的文件导入\caffe\scripts\build\examples\mnist\Release目录
创建一个bat脚本文件,写入如下代码
convert_mnist_data.exe .\train-images.idx3-ubyte .\train-labels.idx1-ubyte .\mnist_train_lmdb
echo.
convert_mnist_data.exe .\t10k-images.idx3-ubyte .\t10k-labels.idx1-ubyte .\mnist_test_lmdb
pause
运行脚本后,生成IMDB文件。
回到\caffe\examples\mnist路径下,创建一个bat文件,写入如下代码
C:\Documents\Caffe\caffe\scripts\build\tools\Release\caffe.exe train --solver=C:\Documents\Caffe\caffe\examples\mnist\lenet_solver.prototxt
Pause
运行脚本文件,即成功运行mnist数据集
运行结果如下:
准确率高达99.07%