Caffe学习笔记(六)—— Windows下训练自己的数据

本文主要介绍:Windows下,根据自己的数据训练自己的网络模型。

1. 图像数据转化为lmdb格式

转化方法及过程参考 ,根据训练数据和测试数据,建立两个文件名及标签txt文件,train.txt和val.txt,然后运行comput_image_mean.bat,生成两个mldb文件夹:mytrainldb 和 myvalldb;

2.计算训练样本均值

(1)编译caffe-windows-master ools 下的compute_image_mean.cpp,生成compute_image_mean.exe;

(2)创建comput_image_mean.txt,添加内容:

SET GLOG_logtostderr=1
bincompute_image_mean.exe  mytrainldb  myimg_mean.binaryproto
pause
第二行有三个参数:

bincompute_image_mean.exe :compute_image_mean.exe 路径

mytrainldb :训练数据转化生成的ldb文件路径

myimg_mean.binaryproto :生成的均值文件路径

注:

<1> 以上路径都是相对路径,需要根据自己的文件路径进行设置,对应的绝对路径为 “comput_image_mean.txt文件夹路径 + 相对路径”;

<2>训练样本转化为mldb文件之前,需要归一化到同一大小,否则出错;

3. 网络定义及设置

以 imagenet网络为例,新的caffe安装包中,没有imagenet_train.prototxt 和 imagenet_val.prototxt 文件,网络定义在 caffe-windows-mastermodelsvlc_reference_caffenet

中,用到train_val.prototxt 和 solver.prototxt 两个文件。

3.1 设置train_val.prototxt 文件

以下路径改为对应的训练数据、均值、测试数据的绝对路径:

3.2 设置 solver.prototxt 文件

注:路径中不能含有中文,同时要注意路径格式,转义字符要用 “/” 或“\”,不能用“”。

3.3 网络训练

(1)创建 train_myimg.txt ,添加内容:

SET GLOG_logtostderr=1
..caffe-windows-masterincaffe.exe  train --solver=.modelsolver.prototxt
pause

第二行两个参数:

..caffe-windows-masterincaffe.exe :caffe安装配置时,生成的caffe.exe,在caffe-windows-masterin 中

train :表示是进行网络训练

--solver=.modelsolver.prototxt : solver.prototxt 文件文件路径

注: 以上路径都是相对路径,需要根据自己的文件路径进行设置,对应的绝对路径为 “train_myimg.txt文件夹路径 + 相对路径”;

(2) train_myimg.txt 改名为 train_myimg.bat 双击运行。

参考:

[1]

[2]



经验分享 程序员 微信小程序 职场和发展