用caffe训练自己的数据集(三)

本文主要参考了:https://blog.csdn.net/heimu24/article/details/53581362

                    https://blog.csdn.net/gaohuazhao/article/details/69568267

六、使用训练好的模型

前两篇博客已经把模型训练好了,本次就是使用已经训练好的模型参数识别图片。

首先在myfile4文件夹下新建images文件夹,把想要检测的图片放入文件夹中,可以用下载的淘宝图片测试。

1、在myfile4文件夹中新建deploy.prototxt文件,内容如下:

name: "myfile4"
layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param{shape:{dim:1 dim:3 dim:32 dim:32}}
  
}

layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  convolution_param {
    num_output: 32
    pad:2
    kernel_size: 5
    stride: 1
  }
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
   name:"relu1"
   type:"ReLU"
   bottom:"pool1"
   top:"pool1"
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "pool1"
  top: "conv2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  convolution_param {
    num_output: 32
    pad:2
    kernel_size: 5
    stride: 1
  }
}
layer {
    name:"relu2"
    type:"ReLU"
    bottom:"conv2"
    top:"conv2"
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: AVE
    kernel_size: 3
    stride: 2
  }
}
layer {
   name:"conv3"
   type:"Convolution"
   bottom:"pool2"
   top:"conv3"
   param{
     lr_mult:1
  }
   param{
     lr_mult:2
  }
  convolution_param {
     num_output:64
     pad:2
     kernel_size:5
     stride:1
  }
}
layer {
  name:"relu3"
  type:"ReLU"
  bottom:"conv3"
  top:"conv3"
}
layer {
  name:"pool3"
  type:"Pooling"
  bottom:"conv3"
  top:"pool3"
  pooling_param {
    pool:AVE
    kernel_size:3
    stride:2
  }
}
layer {
  name: "ip1"
  type: "InnerProduct"
  bottom: "pool3"
  top: "ip1"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 64
  }
}

layer {
  name: "ip2"
  type: "InnerProduct"
  bottom: "ip1"
  top: "ip2"
  param {
    lr_mult: 1
  }
  param {
    lr_mult: 2
  }
  inner_product_param {
    num_output: 10
  }
}

layer {
  name: "prob"
  type: "Softmax"
  bottom: "ip2"
  top: "prob"
}

2、在myfile4文件夹中新建文件synset_work.txt,内容如下:

biao
fajia
kuzi
xiangzi
yizi
dianshi
suannai
xiangshui
hufupin
xiezi

3、在myfile4文件夹下新建demo.sh。内容如下:

./build/examples/cpp_classification/classification.bin examples/myfile4/deploy.prototxt examples/myfile4/my_iter_2000.caffemodel examples/myfile4/mean.binaryproto examples/myfile4/synset_words.txt examples/myfile4/images/222.jpg

4、在caffe目录下运行examples/myfile4/demo.sh  

完成后就会出现识别的结果。自此便完成了自己数据集的训练与识别。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值