繼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)也附加了安裝的二維碼,可以直接掃碼安裝。
推薦閱讀:中國健康網