Mobilenet SSD学习系列(二)Depthwise Convolution的实现

前言

Mobilenet SSD学习系列一(https://blog.csdn.net/ltshan139/article/details/101064590)说过,caffe_ssd框架不支持depthwise convolution的实现,只能用convolution来近似代替,所以会大大增加Mobilenet-SSD模型的推理运行。

Depthwise Convolution的gpu实现

下面来讲如何使得caffe-ssd框架支持Depthwise Convolution的cpu及gpu实现。

1)下载代码

git clone https://github.com/yonghenglh6/DepthwiseConvolution.git depthwise_conv

2)将上面这个开源项目的depthconv实现代码(*.cpp, *.cu 以及*.hpp)拷贝到caffe-ssd对应目录下

cd depthwise_conv

sudo cp -f caffe/src/caffe/layers/depthwise_conv_layer.c* /work/xxx/caffe_ssd/src/caffe/layers/

sudo cp -f caffe/include/caffe/layers/depthwise_conv_layer.hpp /work/xxx/caffe_ssd/include/caffe/layers/

 3)重新对caffe-ssd框架代码进行编译:

sudo make clean
sudo make -j8 
sudo make pycaffe -j8

      使得caffe-ssd真正支持depthwise convolution layer的支持。

4)最后一步是 修改mobilenet-SSD下面的deploy.prototxt

sudo vi voc/MobileNetSSD_deploy.prototxt 

a)把13个“engine: CAFFE” 重新都注释掉

b)conv1/dw到conv13/dw 的type从”Convolution”替换成”DepthwiseConvolution”,总共也有13个地方。

下面以conv1/dw为例来看修改内容如红框所示。

 效果验证

首先在demo.py的detect函数中添加time模块如下图所示。

在gpu模式下,使用原始的deploy.prototxt,即用convlution来近似代替depthwise convolution,其检测测试图片(./images) 所花时间如下所示:

time=0.0463089942932s
time=0.0358200073242s
time=0.0369169712067s
time=0.0367810726166s
time=0.0381460189819s
time=0.037379026413s
time=0.0422718524933s

而基于update的deploy.prototxt,即真正使用depthwise convolution layer的实现后,同样测试图片识别 所消耗时间如下所示。

time=0.036953878403s
time=0.00506377220154s
time=0.00571703910828s
time=0.0045220661163s
time=0.0079579162598s
time=0.0368349552155s
time=0.0831339359283s

可以看出 后者方式所化时间大为减少。

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ltshan139

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值