【AlexNet】模型训练与测试导读

来源:互联网 发布:lnmp php日志 编辑:程序博客网 时间:2024/05/17 03:55

【AlexNet】模型训练与测试导读

Label 深度学习 AlexNet训练与测试

假设本机上已经配置好了caffe框架,且已了解AlexNet模型的架构,本篇旨在引导读者实现模型的训练与测试,训练集【ILSVRC2012】

一.数据处理
ILSVRC2012数据下载:http://pan.baidu.com/s/1jHqYJw6 密码: ia4d;解压密码:367660588;
这份是ILSVRC2012年比赛所有的数据,下载解压约占空间141G。
资料转自:http://www.thinkface.cn/thread-4199-1-1.html;

其次需要下载好数据集的标记文件(共1000类):get_ilsvrc_aux.sh
路径:https://github.com/BVLC/caffe/tree/master/data/ilsvrc12;
包括:train.txt【训练样本名->数字标记】;val.txt【校验样本名->数字标记】;test.txt【测试样本名->数字标记】;sysets.txt【1000个数字标记对应的1000个 ASCII标记】;synset_words.txt【1000个 ASCII标记对应的各类名】;imagenet_mean.binaryproto【训练数据的均值】;

在应用数据集到模型训练前,需预处理(数据集图像尺寸调整至256*256和去均值):
处理脚本:https://github.com/BVLC/caffe/tree/master/examples/imagenet:create_imagenet.sh;
计算均值脚本:make_imagenet_mean.sh;-》可生成imagenet_mean.binaryproto;
此处需要注意,应修改脚本开头的相关路径,与自己的配置环境和数据集路径一致。两项预处理分别调用了https://github.com/BVLC/caffe/tree/master/tools的convert_imageset.cpp和compute_image_mean.cpp,有兴趣的可以单独阅读。

二.模型定义
文章中所述的AlexNet【也可参考我的博文:【AlexNet解读】ImageNet Classification withDeep Convolutional Neural Networks】模型,被描述在:
https://github.com/BVLC/caffe/tree/master/models/bvlc_reference_caffenet:train_val.prototxt;
group: 2,该层运算在2个GPU上跑;
mirror: false/true,数据是否镜像;
include: TRAIN/TEST,该层仅包含在训练过程中,或者测试过程中;

初始化参数解读:solver.prototxt;训练用train,训练中的测试用val,训练好后测试test
net: “models/bvlc_reference_caffenet/train_val.prototxt” 【定义好的模型】
test_iter: 1000 【测试迭代1000次,每次50张图,定义在train_val.prototxt,共50,000】
test_interval: 1000 【迭代1,000次,测试(校验)一次】
base_lr: 0.01 【初始化学习速率】
lr_policy: “step” 【学习速率更改周期名‘步长’】
gamma: 0.1 【学习速率相关参数】
stepsize: 100000 【每100,000次迭代,学习速率更改一次】
display: 20 【每20次迭代显示一次结果】
max_iter: 450000 【最多迭代450,000次】
momentum: 0.9 【学习速率更改的相关参数】
weight_decay: 0.0005 【学习速率更改的相关参数】
snapshot: 10000 【每10,000次迭代保存一次当前模型】
snapshot_prefix: “models/bvlc_reference_caffenet/caffenet_train” 【当前模型的保存地址】
solver_mode: GPU 【采用GPU】

三.训练模型
编写训练脚本 train_caffenet.sh:
./build/tools/caffe train \
–solver=models/bvlc_reference_caffenet/solver.prototxt
运算时间查看:
./build/tools/caffe time –model=models/bvlc_reference_caffenet/train_val.prototxt
也可以在某个训练层后接着训练:
./build/tools/caffe train –solver=models/bvlc_reference_caffenet/solver.prototxt
–snapshot=models/bvlc_reference_caffenet/caffenet_train_iter_10000.solverstate

或者下载训练好的模型,并做测试:http://blog.csdn.net/xiequnyi/article/details/52151243

另外参考的博文:http://blog.csdn.net/drdeep/article/details/50835974

0 0