深度学习-CAFFE利用CIFAR10网络模型训练自己的图像数据获得模型-3结合caffe中的CIFAR10修改相关配置文件并训练

分别将cifar10_quick_train_test.prototxtcifar10_quick_solver.prototxttrain_quick.sh三个文件 copy至自己所建立的文件目录, 如:testCreateLmDB。并修改成自己的文件名:my_quick_train_test.prototxtmy_quick_solver.prototxtmy _train_quick.sh.它们分别是网络结构脚本文件 、超参配置脚本文件 和训练脚本文件。分别修改它们:

 

a.my_quick_train_test.prototxt网络结构脚本文件

name: "my_quick"  #修改成自己的名字
layer {
  name: "myimg"   #修改成自己的名字
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
    mean_file: "examples/testCreateLmDB/my_mean.binaryproto" #均值所在目录
  }
  data_param {
    source: "examples/testCreateLmDB/my_train_lmdb"          #训练数据所在目录
    batch_size: 10                                           #自己的数据量小,修改成10
    backend: LMDB
  }
}
layer {
  name: "myimg"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  transform_param {
    mean_file: "examples/testCreateLmDB/my_mean.binaryproto" #均值所在目录
  }
  data_param {
    source: "examples/testCreateLmDB/my_val_lmdb"            #测试数据所在目录
    batch_size: 10                                           #自己的数据量小,修改成10
    backend: LMDB
  }
}

#训练数据采用该网络结构,所以不变,不用修改
.................
.................
layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top: "ip2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 5                #自己的数据只有五类,所以修改成5
    weight_filler {
      type: "gaussian"
      std: 0.1
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "accuracy"
  type: "Accuracy"
  bottom: "ip2"
  bottom: "label"
  top: "accuracy"
  include {
    phase: TEST
  }
}
layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "ip2"
  bottom: "label"
  top: "loss"
}

b.my_quick_solver.prototxt超参配置脚本文件

# reduce the learning rate after 8 epochs (4000 iters) by a factor of 10

# The train/test net protocol buffer definition
#【1】改为你自己的网络模型配置文件的目录  
net: "examples/testCreateLmDB/my_quick_train_test.prototxt" 
# test_iter specifies how many forward passes the test should carry out.
# In the case of MNIST, we have test batch size 100 and 100 test iterations,
# covering the full 10,000 testing images.
test_iter: 10     #【2】预测阶段迭代次数,我们设为10,这样就可以覆盖我们的100张测试样
# Carry out testing every 500 training iterations.
test_interval: 50 #【3】由于我们只有400张训练样本,所以我们将此改为50,每迭代50次,进行一次测试
# The base learning rate, momentum and the weight decay of the network.
base_lr: 0.001    #【4】权值学习率,其实就是在反向传播阶段,权值每次的调整量的程度  
momentum: 0.9
weight_decay: 0.004
# The learning rate policy
lr_policy: "fixed" #【5】在整个过程中,我们使用固定的学习率,当然,你也可以试一下可变学习率
# Display every 100 iterations
display: 20
# The maximum number of iterations
max_iter: 5000
# snapshot intermedate results
snapshot: 4000
snapshot_format: HDF5
snapshot_prefix: "examples/testCreateLmDB/my_quick" #【5】模型存放的位置
# solver mode: CPU or GPU
solver_mode: GPU 

c. my _train_quick.sh训练脚本文件

#!/usr/bin/env sh
set -e

TOOLS=./build/tools

$TOOLS/caffe train \
  --solver=examples/testCreateLmDB/my_quick_solver.prototxt  $@  #注意 该超参数所在的目录

d.训练

在终端caffe目录下执行修改后的训练脚本

 

./examples/testCreateLmDB/my_train_quick.sh 


至此,可以开始训练。

友情提醒:该步骤配置文件 较多,所修改的地方较多,一定要小心,本人在玩这过程中,老出问题。都是目录所在路径没有修改好所造成的。




  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值