windows+caffe(四)——创建模型并编写配置文件+训练和测试

时间:2021-07-29 08:11:16

1.模型就用程序自带的caffenet模型,位置在 models/bvlc_reference_caffenet/文件夹下, 将需要的两个配置文件,复制到myfile文件夹内

windows+caffe(四)——创建模型并编写配置文件+训练和测试

2. 修改solver.prototxt(用notepad)

net: "examples/myfile/train_val.prototxt"    #
test_iter: 2
test_interval: 50
base_lr: 0.001
lr_policy: "step"
gamma: 0.1
stepsize: 100
display: 20
max_iter: 500
momentum: 0.9
weight_decay: 0.005
solver_mode: CPU      #我用的是cpu所以改成了cpu

3.修改train_val.prototxt

name: "CaffeNet"
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mirror: true
crop_size: 227
mean_file: "examples/myfile/mean.binaryproto"
}
# mean pixel / channel-wise mean instead of mean image
# transform_param {
# crop_size: 227
# mean_value: 104
# mean_value: 117
# mean_value: 123
# mirror: true
# }
data_param {
source: "examples/myfile/train_db"
batch_size: 256
backend: LMDB
}
}
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
mirror: false
crop_size: 227
mean_file: "examples/myfile/mean.binaryproto"
}
# mean pixel / channel-wise mean instead of mean image
# transform_param {
# crop_size: 227
# mean_value: 104
# mean_value: 117
# mean_value: 123
# mirror: false
# }
data_param {
source: "examples/myfile/test_db"
batch_size: 50
backend: LMDB
}
}

其他不需要改变。

4.训练和测试(具体见langb2014的http://blog.csdn.net/langb2014/article/details/50458014)

(1)运行.sh

cygwin到caffe根目录下输入

bin/caffe train -solver examples/myfile/solver.prototxt

解释:

【1】bin/caffe   你的caffe.exe所在目录

windows+caffe(四)——创建模型并编写配置文件+训练和测试

以下就不说了看langb2014大神的特别清楚!!!

结果(我的还没有训练完,因为我的是只有cpu运行的超级慢):

windows+caffe(四)——创建模型并编写配置文件+训练和测试

看大神的结果:

windows+caffe(四)——创建模型并编写配置文件+训练和测试

到现在,成功运行了一个caffe例子

(2)运行.bat

新建run_test.bat,内容为

D:/deeptools/caffe-windows-master/bin/caffe.exe train --solver=D:/deeptools/caffe-windows-master/examples/myfile/wintest/solver.prototxt
pause

然后solver.prototxt和train_val.prototxt都改成了绝对路径,其他的没变