windows10conda2使用caffe训练训练自己的数据

my0213 my0213     2022-12-24     449

关键词:

首先得到了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

欢迎批评指正。

 

使用caffe的cifar10网络模型训练自己的图片数据

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

caffe_ssd学习-用自己的数据做训练

几乎没用过linux操作系统,不懂shell编程,linux下shell+windows下UltraEdit勉勉强强生成了train.txt和val.txt期间各种错误辛酸不表,照着examples/imagenet/readme勉勉强强用自己的数据集把reference_caffenet训起来了,小笔记本的风扇又开始呼呼呼... 查看详情

caffe的学习和使用·一」--使用caffe训练自己的数据

学习知识的一种方式是先会用然后再问为什么。在安装完成caffe,根据caffe的提示下载完mnist训练测试数据,并且运行lenet训练模型之后,摆在眼前的问题就是我怎么用caffe训练自己的数据啊,mnist的数据通过脚本就可以下载创建成... 查看详情

windows环境caffe安装配置步骤(无gpu)及mnist训练

...手熟悉Caffe,考虑到直接上手Ubuntu会有些难度,所以首先在windows环境下打个基础。有个插曲,台式机由于某些原因只能保持在32位系统,编译caffe.cpp时才发现系统不兼容,然后才换到64位的笔记本上进行操作。 前期准备: 查看详情

Caffe:如何使用已经训练好的模型一次检查多个数据集的准确性?

】Caffe:如何使用已经训练好的模型一次检查多个数据集的准确性?【英文标题】:Caffe:HowtocheckaccuraciesofmultipleDatasetswithalreadytrainedmodelatatime?【发布时间】:2016-11-0413:41:12【问题描述】:在Caffe框架中使用2个类别的10k图像训练LeNe... 查看详情

从零到一:caffe-windows(cpu)配置与利用mnist数据集训练第一个caffemodel

一、前言   本文会详细地阐述caffe-windows的配置教程。由于博主自己也只是个在校学生,目前也写不了太深入的东西,所以准备从最基础的开始一步步来。个人的计划是分成配置和运行官方教程,利用自己的数据集进... 查看详情

如何在 caffe 中训练/测试我自己的数据集?

...和标签是(-1,+1)保存在data.mat中)。但是,我不太明白如何使用caffe来实现自己的数据集?有没有分步 查看详情

华农华迪实训训练-获得词频前10的字段数据-requests+sparkrdd(代码片段)

题目1、网络数据采集,使用requests或者scrapy爬取数据,存储到一个文本文件数据源文件.txt中。2、使用SparkRDD或者SparkSql,读取数据源文件.txt内容,对某一个字段的数据进行统计,获得词频前10的字段数据。把... 查看详情

华农华迪实训训练-获得词频前10的字段数据-requests+sparkrdd(代码片段)

题目1、网络数据采集,使用requests或者scrapy爬取数据,存储到一个文本文件数据源文件.txt中。2、使用SparkRDD或者SparkSql,读取数据源文件.txt内容,对某一个字段的数据进行统计,获得词频前10的字段数据。把... 查看详情

使用caffe训练mnist数据集-caffe教程实战

个人认为学习一个陌生的框架,最好从例子开始,所以我们也从一个例子开始。学习本教程之前,你需要首先对卷积神经网络算法原理有些了解,而且安装好了caffe卷积神经网络原理参考:http://cs231n.stanford.edu/syllabus.htmlUbuntu安装... 查看详情

使用 Caffe 内存层不会产生一致和确定性的结果

...icresults【发布时间】:2016-02-1812:42:35【问题描述】:我在Windows764位机器上使用适用于windows的Caffe框架(从here下载)。我在VisualStudioCommunity2013中使用C++。我使用预训练的Go 查看详情

如何使用opencvdnn模块调用caffe预训练模型?(代码片段)

QStringmodelPrototxt="D:\\Qt\\qmake\\CaffeModelTest\\caffe\\lenet.prototxt";QStringmodelBin="D:\\Qt\\qmake\\CaffeModelTest\\caffe\\snapshot_iter_10000.caffemodel";QStringimageFile= 查看详情

如何使用caffe训练mnist后得到的lenet

参考技术A你好你可以微信搜索北京健康之家后关注,专门帮你解决困扰你健康的问题 查看详情

使用 Caffe 训练数据集时多次加载 HDF5 文件

】使用Caffe训练数据集时多次加载HDF5文件【英文标题】:HDF5fileisloadedmultipletimeswhentrainingdatasetusingCaffe【发布时间】:2018-02-0803:12:46【问题描述】:我正在使用hdf5文件训练数据集,日志显示hdf5文件已加载3次。我想知道这是为什... 查看详情

是否可以在没有任何训练的情况下使用 Caffe Only 进行分类?

】是否可以在没有任何训练的情况下使用CaffeOnly进行分类?【英文标题】:IsitpossibletouseCaffeOnlyforclassificationwithoutanytraining?【发布时间】:2016-07-2612:57:45【问题描述】:有些用户可能会将此视为基于意见的问题,但如果您仔细观... 查看详情

caffec++中使用训练好的caffe模型,classification工程生成动态链接库——caffe学习六(代码片段)

除了在opencvdnn中使用训练好的model,还可以直接通过classification.exe去查看单张图的训练结果。但是我在使用opencvdnn的时候,发现里面输出的结果和classification.exe并不一样,一时找不到原因,于是还是考虑将classificat... 查看详情

使用caffe训练自己的cnn

 现在有这样的一个场景:给你一张行人的矩形图片,要你识别出该行人的性别特侦。 分析:(1),行人的姿态各异,变化多端。很难提取图像的特定特征(2),正常人判别行人的根据是身材比例。(如果是冬天的情况... 查看详情

window10下caffe(gpu版)安装问题记录

...够顺利的安装,推荐使用visualstudio2013+cuda8.0+cudnn5.1。另外windows下pycaffe只能够通过python2来调用,使用anaconda3的话需要新建一个python2的虚拟环境来安装caffe问题1:顺利复制完caffe路径到自身py2环境的site-package文件夹之后,在importcaf... 查看详情