首先得到了https://blog.csdn.net/gybheroin/article/details/72581318系列博客的帮助。表示感激。

关于安装caffe已在之前的博客介绍,自用可行,https://www.cnblogs.com/MY0213/p/9225310.html

1.数据源

首先使用的数据集为人脸数据集,可在百度云自行下载:

链接:https://pan.baidu.com/s/156DiOuB46wKrM0cEaAgfMw 密码:1ap0

将train.zip解压可得数据源,label文件是val.txt和train.txt。

2.将图片数据做成lmdb数据源

SET GLOG_logtostderr=1

SET RESIZE_HEIGHT=227
SET RESIZE_WIDTH=227 "convert_imageset" --resize_height=227 --resize_width=227 --shuffle "train/" "train.txt" "mtraindb"
"convert_imageset" --resize_height=227 --resize_width=227 --shuffle "val/" "val.txt" "mvaldb" pause

 详见face_lmdb.bat,将数据做成同等大小的数据。

3. 得到图像均值

SET GLOG_logtostderr=1

"compute_image_mean" "mtraindb" "train_mean.binaryproto"

pause

详见mean_face.bat

训练时先做减均值的操作,可能对训练效果有好处

这里可以用固定的图片均值,是多少可以直接百度谷歌,这一步也可以不做,唐宇迪大神说影响不大。

4. 图像训练

SET GLOG_logostderr=1
caffe train --solver=solver.prototxt
pause

 详见train.bat

net: "train.prototxt"
test_iter: 100
test_interval: 1000
# lr for fine-tuning should be lower than when starting from scratch
base_lr: 0.001
lr_policy: "step"
gamma: 0.1
# stepsize should also be lower, as we're closer to being done
stepsize: 1000
display: 50
max_iter: 10000
momentum: 0.9
weight_decay: 0.0005
snapshot: 1000
snapshot_prefix: "model"
# uncomment the following to default to CPU mode solving
# solver_mode: CPU

详见solver.prototxt

关于solver.prototxt的内涵可查看

https://blog.csdn.net/qq_27923041/article/details/55211808

#############################  DATA Layer  #############################
name: "face_train_val"
layer {
top: "data"
top: "label"
name: "data"
type: "Data"
data_param {
source: "mtraindb"
backend:LMDB
batch_size: 64
}
transform_param {
mean_file: "train_mean.binaryproto"
mirror: true
}
include: { phase: TRAIN }
} layer {
top: "data"
top: "label"
name: "data"
type: "Data"
data_param {
source: "mvaldb"
backend:LMDB
batch_size: 64
}
transform_param {
mean_file: "train_mean.binaryproto"
mirror: true
}
include: {
phase: TEST
}
}
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 96
kernel_size: 11
stride: 4
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "conv1"
top: "conv1"
}
layer {
name: "norm1"
type: "LRN"
bottom: "conv1"
top: "norm1"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layer {
name: "pool1"
type: "Pooling"
bottom: "norm1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "pool1"
top: "conv2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 2
kernel_size: 5
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0.1
}
}
}
layer {
name: "relu2"
type: "ReLU"
bottom: "conv2"
top: "conv2"
}
layer {
name: "norm2"
type: "LRN"
bottom: "conv2"
top: "norm2"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layer {
name: "pool2"
type: "Pooling"
bottom: "norm2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "conv3"
type: "Convolution"
bottom: "pool2"
top: "conv3"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu3"
type: "ReLU"
bottom: "conv3"
top: "conv3"
}
layer {
name: "conv4"
type: "Convolution"
bottom: "conv3"
top: "conv4"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0.1
}
}
}
layer {
name: "relu4"
type: "ReLU"
bottom: "conv4"
top: "conv4"
}
layer {
name: "conv5"
type: "Convolution"
bottom: "conv4"
top: "conv5"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 1
kernel_size: 3
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0.1
}
}
}
layer {
name: "relu5"
type: "ReLU"
bottom: "conv5"
top: "conv5"
}
layer {
name: "pool5"
type: "Pooling"
bottom: "conv5"
top: "pool5"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "fc6"
type: "InnerProduct"
bottom: "pool5"
top: "fc6"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.005
}
bias_filler {
type: "constant"
value: 0.1
}
}
}
layer {
name: "relu6"
type: "ReLU"
bottom: "fc6"
top: "fc6"
}
layer {
name: "drop6"
type: "Dropout"
bottom: "fc6"
top: "fc6"
dropout_param {
dropout_ratio: 0.5
}
}
layer {
name: "fc7"
type: "InnerProduct"
bottom: "fc6"
top: "fc7"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.005
}
bias_filler {
type: "constant"
value: 0.1
}
}
}
layer {
name: "relu7"
type: "ReLU"
bottom: "fc7"
top: "fc7"
}
layer {
name: "drop7"
type: "Dropout"
bottom: "fc7"
top: "fc7"
dropout_param {
dropout_ratio: 0.5
}
}
layer {
name: "fc8-expr"
type: "InnerProduct"
bottom: "fc7"
top: "fc8-expr"
param {
lr_mult: 10
decay_mult: 1
}
param {
lr_mult: 20
decay_mult: 0
}
inner_product_param {
num_output: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "fc8-expr"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc8-expr"
bottom: "label"
top: "loss"
}

详见train.prototxt,也就是将alexnet中最后的1000变为2就可以了。

这个过程需要5天左右(我用的cpu),可以直接用已有模型alexnet_iter_50000_full_conv.caffemodel

5. 测试

可用run_face_detect_batch.py测试人脸检测效果。

6. 总结

这个网络测试时特别慢,用的是slipping window的方法。下面的文章再介绍快速一点的faster rcnn 及FPN。

slipping window中用了Casting a Classifier into a Fully Convolutional Network的方法。这一方法在其他网络中也可用。

关于rcnn的演进,可见https://www.cnblogs.com/MY0213/p/9460562.html

欢迎批评指正。

windows10 conda2 使用caffe训练训练自己的数据的更多相关文章

  1. caffe简易上手指南(二)—— 训练我们自己的数据

    训练我们自己的数据 本篇继续之前的教程,下面我们尝试使用别人定义好的网络,来训练我们自己的网络. 1.准备数据 首先很重要的一点,我们需要准备若干种不同类型的图片进行分类.这里我选择从ImageNet ...

  2. caffe绘制训练过程的loss和accuracy曲线

    转自:http://blog.csdn.net/u013078356/article/details/51154847 在caffe的训练过程中,大家难免想图形化自己的训练数据,以便更好的展示结果.如 ...

  3. cudnn升级之后caffe无法训练的问题

    由于安装新版本的TensorFlow需要cudnn6.0因此用6.0将原来的 5.0替换了,后来又用之前编译好的caffe进行训练,发现caffe会去找5.0的cudnn,然后就报错了,不能正常训练. ...

  4. 实践详细篇-Windows下使用Caffe训练自己的Caffemodel数据集并进行图像分类

    三:使用Caffe训练Caffemodel并进行图像分类 上一篇记录的是如何使用别人训练好的MNIST数据做训练测试.上手操作一边后大致了解了配置文件属性.这一篇记录如何使用自己准备的图片素材做图像分 ...

  5. caffe 如何训练自己的数据图片

    申明:此教程加工于caffe 如何训练自己的数据图片 一.准备数据 有条件的同学,可以去imagenet的官网http://www.image-net.org/download-images,下载im ...

  6. Windows平台上Caffe的训练与学习方法(以数据库CIFAR-10为例)

    Windows平台上Caffe的训练与学习方法(以数据库CIFAR-10为例) 在完成winodws平台上的caffe环境的搭建之后,亟待掌握的就是如何在caffe中进行训练与学习,下面将进行简单的介 ...

  7. python+caffe训练自己的图片数据流程

    1. 准备自己的图片数据 选用部分的Caltech数据库作为训练和测试样本.Caltech是加州理工学院的图像数据库,包含Caltech101和Caltech256两个数据集.该数据集是由Fei-Fe ...

  8. CAFFE学习笔记(五)用caffe跑自己的jpg数据

    1 收集自己的数据 1-1 我的训练集与测试集的来源:表情包 由于网上一幅一幅图片下载非常麻烦,所以我干脆下载了两个eif表情包.同一个表情包里的图像都有很强的相似性,因此可以当成一类图像来使用.下载 ...

  9. Caffe初试(三)使用caffe的cifar10网络模型训练自己的图片数据

    由于我涉及一个车牌识别系统的项目,计划使用深度学习库caffe对车牌字符进行识别.刚开始接触caffe,打算先将示例中的每个网络模型都拿出来用用,当然这样暴力的使用是不会有好结果的- -||| ,所以 ...

随机推荐

  1. 四则运算<C++>

    代码: #include<iostream> #define N 30 using namespace std; void main() { cout<<"***** ...

  2. Leetcode题库——27.移除元素

    @author: ZZQ @software: PyCharm @file: removeElement.py @time: 2018/9/23 14:04 要求:给定一个数组 nums 和一个值 v ...

  3. Java 经典 书籍

    1.<你的灯还亮着么> 方法论 2.<程序员修炼之道 从小工到专家> 方法论 3.<发布!软件的设计与部署> 案例&经验总结 4.<思考,快与慢> ...

  4. js作用域相关笔记

    1.js引擎.编译器.作用域. 引擎:负责JS全过程的编译和执行: 编译器:负责语法分析和代码生成: 作用域:负责收集并维护声明组成的查询,以及当前执行代码对这些变量的访问权限(简言之,作用域就是用于 ...

  5. SQL语句中order_by_、group_by_、having的用法区别

    order by 从英文里理解就是行的排序方式,默认的为升序. order by 后面必须列出排序的字段名,可以是多个字段名. group by 从英文里理解就是分组.必须有“聚合函数”来配合才能使用 ...

  6. 高可用集群(crmsh详解)http://www.it165.net/admin/html/201404/2869.html

    crmsh是pacemaker的命令行接口工具,执行help命令,可以查看shell接口所有的一级命令和二级命令,使用cd 可以切换到二级子命令的目录中去,可以执行二级子命令 在集群中的资源有四类:p ...

  7. json对象与json字符串的区别

    最近糟了这个坑,同一个方法,android和ios返回的数据不一样,一个是json字符串,另一个是json对象(至于为什么后台返回的是json对象,还没找到原因,但是我看到的后台的代码是有在返回之前给 ...

  8. 服务 在初始化安装时发生异常:System.IO.FileNotFoundException: 未能加载文件或******

    这个问题是在用installutil.exe安装服务时候碰到的 解决方法就是把installutil.exe文件直接复制到要安装的目录下 installutil.exe的所在位置 windows/mi ...

  9. Qt宏Q_OBJECT展开记录

    c++中的宏 #define A 3.14 展开后把A替换为B #define A(a) #a 展开后用a的字符串替换A(a) #define A(a) a##B 展开后把a和B的字符串连接起来后替换 ...

  10. 微信小程序 功能函数 替换字符串内的指定字符

    var str = 'abcadeacf'; var str1 = str.replace('a', 'o'); alert(str1);    // 打印结果: obcadeacf   var st ...