1.首先下载官方BVLC版本的caffe ,https://github.com/BVLC/caffe/tree/windows
2.CMAKE。需要3.4版本以上,我用的是3.9.6
下载地址:https://cmake.org/files/v3.9/cmake-3.9.6-win64-x64.msi
3.Anaconda。目前官方的版本是Anaconda 3.6和2.7,就是说内置了 Python2.7 or 3.6。 喜欢高版本的朋友注意了,3.6caffei不支持。所以你要么在历史档案中下Anaconda3-4.2.0-Windows-x86_64.exe,要么参照http://blog.csdn.net/cym1990/article/details/78563349下个3.6版本的,然后重新安装Anaconda的环境为 PYTHON3.5。当然2.7版本的就可以了。
下载地址:https://repo.continuum.io/archive/Anaconda3-4.2.0-Windows-x86_64.exe
然后用notepad修改caffe路径下scripts文件下build_win.cmd
修改第8行为,if NOT DEFINED WITH_NINJA set WITH_NINJA=0,表示使用cl编译器,而非NINJA
修改第9行为,if NOT DEFINED CPU_ONLY set CPU_ONLY=0,表示编译GPU版本caffe
修改第74行为,if NOT DEFINED WITH_NINJA set WITH_NINJA=0,表示使用cl编译器,而非NINJA
修改第76行为,if NOT DEFINED CPU_ONLY set CPU_ONLY=0,表示编译GPU版本caffe
修改完毕后,返回上级目录,cmd下执行下面的命令。
下载https://github.com/willyd/caffe-builder/releases
放到路径C:\Users\lcc\.caffe\dependencies\download
根据自己下载修改
在caffe文件下 cmd下执行scripts\build_win.cmd
最后
完毕后在caffe下可以找到Caffe.sln,使用VS2015打开,对整个工程进行编译即可。完毕后就会生成需要的库文件。
3.测试caffe.exe
参见Windows下VS2015编译caffe(CPU ONLY)
(1)下载MNIST数据库https://pan.baidu.com/s/1o7YrhKe,解压缩后将mnist-test-leveldb与mnist-train-leveldb文件夹放到\examples\mnist下。注意
(2)修改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:/Caffe/caffe/examples/mnist/mnist-train-leveldb"
batch_size: 64
backend:LEVELDB
}
}
layer {
name: "mnist"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
scale: 0.00390625
}
data_param {
source:"C:/Caffe/caffe/examples/mnist/mnist-test-leveldb"
batch_size: 100
backend:LEVELDB
}
}
注意:修改4个红色字体文字,相信你看得懂,就是刚才拷贝的两个文件夹的绝对路径;以及两处格式
(3)修改lenet_solver.prototxt文件:
# The train/test net protocolbuffer definition
net: "C:/Caffe/caffe/examples/mnist/lenet_train_test.prototxt"
# test_iter specifies how manyforward passes the test should carry out.
# In the case of MNIST, we havetest batch size 100 and 100 test iterations,
# covering the full 10,000 testingimages.
test_iter: 100
# Carry out testing every 500training iterations.
test_interval: 500
# The base learning rate, momentumand 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:/Caffe/caffe/examples/mnist/lenet"
# solver mode: CPU or GPU
solver_mode: CPU
注意:修改两处个红色字体文字,相信你看得懂,就是修改文件或者文件夹的绝对路径;如果你的硬件不支持GPU编程,最后一句修改为CPU。
(4)在minist文件夹下编写批处理文件run.bat,内容如下:
D:\caffe1\tools\Debug\caffe-d.exe train --solver=D:\caffe1\examples\mnist\lenet_solver.prototxt
Pause
说明:第一行,就是执行你编译得到的caffe.exe,所以需要换成你的caffe.exe的绝对路径。
注意:
· 斜杠必须使用backslash:\。使用Slash:/会出错。
· train 和—solver之间有一空格,不能省略。无空格会出错。
(5)双击run.bat程序能够运行,并且之后也不会报错,那么恭喜你,Caffe-Windows配置成功了。
转载:https://blog.csdn.net/flowrush/article/details/81480535