caffe学习日记--lesson4:windows下caffe DEMO (mnist and cifar10)

caffe学习日记--lesson4:windows下caffe DEMO (mnist and cifar10)


1.下载数据
mnist官网:http://yann.lecun.com/exdb/mnist/
2.数据格式转化
使用编译得到的convent_mnist_data.exe程序,得到lmdb格式的数据(lmdb的内存消耗是leveldb1.1倍,但是lmdb的速度比leveldb10%15%,重要的是lmdb允许多种训练模型同时读取同一组数据集。

..\..\Build\x64\Release\convert_mnist_data.exe train-images.idx3-ubyte  train-labels.idx1-ubyte .\lmdb\train_lmdb

..\..\Build\x64\Release\convert_mnist_data.exe t10k-images.idx3-ubyte  t10k-labels.idx1-ubyte .\lmdb\test_lmdb

pause
简单说明:exe  数据  标签 保存的到文件 (其中lmdb目录实现建立好)
..\  相对路径回到上一级目录
.\ 当前目录下,

3.配置文件的编写
3.1 lenet_train_test.prototxt
name: "LeNet"
layer {
  name: "mnist"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
  transform_param {
    scale: 0.00390625
  }
  data_param {
    source: "../../data/mnist/lmdb/train_lmdb"
    batch_size: 64
    backend: LMDB
  }
}
layer {
  name: "mnist"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
  transform_param {
    scale: 0.00390625
  }
  data_param {
    source: "../../data/mnist/lmdb/test_lmdb"
    batch_size: 100
    backend: LMDB
  }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  convolution_param {
    num_output: 20
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  convolution_param {
    num_output: 50
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 2
    stride: 2
  }
}
layer {
  name: "ip1"
  type: "InnerProduct"
  bottom: "pool2"
  top: "ip1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 500
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "ip1"
  top: "ip1"
}
layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top: "ip2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 10
    weight_filler {
      type: "xavier"
    }
    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"
}

3.2 lenet_solver.prototxt
net: "lenet_train_test.prototxt"  

test_iter: 100

test_interval: 500

base_lr: 0.01
momentum: 0.9
weight_decay: 0.0005

lr_policy: "inv"
gamma: 0.0001
power: 0.75

display: 100

max_iter: 10000

snapshot: 5000
snapshot_prefix: "./models/lenet"

solver_mode: GPU

3.3 bat
..\..\Build\x64\Release\caffe train --solver=lenet_solver.prototxt

pause
具体语法参考:http://www.cnblogs.com/denny402/tag/caffe/
作为学术研究人员,应当熟练书写各种prototxt文件。
4.训练
注意bat文件和solver.prototxt,lenet_train_test.prototxt 文件放在同一级目录,且新建文件夹models用来保存caffemodel
运行bat,即可训练模型,得到caffemodel



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值