百度开源移动端深度学习框架,手机百度内可体验!
继PaddlePaddle之后,百度研发的移动端深度学习框架也加入Github开源网站啦!百度方面表示,这一框架致力于让卷积神经网络可极度简单的部署在手机端。目前正在手机百度内运行。支持iOS gpu计算,体积小,速度快。
体积 armv7 340k+
速度 iOS GPU mobilenet 可以达到 40ms、squeezenet 可以达到 30ms
我们先来看看运行效果:
看完Demo,如果你想了解demo源码实现可以往下看,它位于examples目录中。
运行examples文件
复制项目
安装apk\ipa文件或者导入IDE.
运行
开发或使用要求
安卓用户:安装NDK
安装Cmake.
Android NDK CMake 文件
安装Protocol Buffers.
如何使用MDL lib
在OSX或者Linux上运行测试
在项目中使用MDL lib
在MDL lib使用多线程
开发
编译android的MDL源码
编译iOS的MDL源码
模型转换
MDL需要兼容的型号才能使用。要获得MDL兼容模型,程序员可以使用百度的脚本将其他深度学习工具训练的模型转换为MDL模型。
百度方面强烈建议使用PaddlePaddle模型。
将PaddlePaddle模型转换为mdl格式
Paddlepaddle型号可以转换为MDL型号
将caffemodel转换为mdl格式
#Convert model.prototxt and model.caffemodel to model.min.json and data.min.bin that mdl use
./build.sh mac
cd ./build/release/x86/tools/build
# copy your model.prototxt and model.caffemodel to this path
./caffe2mdl model.prototxt model.caffemodel
# if you want to test the model produced by this script, provide color value array of an image as the third parameter ,like this:
./caffe2mdl model.prototxt model.caffemodel data
# the color value should in order of rgb,and transformed according to the model.
# then you will get a new data.min.bin with test data inside
# after this command, model.min.json data.min.bin will be created in current
# some difference step you need to do if you convert caffe model to iOS GPU format
# see this:
open iOS/convert/iOSConvertREADME.md
特征
一键部署,脚本参数就可以切换ios或者android
支持iOS gpu运行MobileNet、squeezenet模型
已经测试过可以稳定运行MobileNet、GoogLeNet v1、squeezenet模型
体积极小,无任何第三方依赖。纯手工打造。
提供量化脚本,对32位float转8位uint直接支持,模型体积量化后4M上下
与ARM相关算法团队线上线下多次沟通,针对ARM平台会持续优化
NEON使用涵盖了卷积、归一化、池化所有方面的操作
汇编优化,针对寄存器汇编操作具体优化
loop unrolling 循环展开,为提升性能减少不必要的CPU消耗,全部展开判断操作
将大量繁重的计算任务前置到overhead过程
MDL使用的是宽松的MIT开源协议。
如果你不想了解CNN细节实现,百度在项目开源页面(https://github.com/baidu/mobile-deep-learning)也附加了安装的二维码,可以直接扫码安装。
推荐阅读:永州热线