0
雷鋒網 AI科技評論消息,日前,百度在 GitHub 上開源了移動端深度學習框架 mobile-deep-learning(MDL)的全部代碼以及腳本,這項研究旨在讓卷積神經網絡(CNNC)能更簡單和高速的部署在移動端,支持iOS GPU,目前已經在百度APP上有所使用。雷鋒網 AI科技評論將GitHub上的具體內容整理如下:
大小:340k+(在arm v7上)
速度:對于 iOS Metal GPU Mobilenet,速度是40ms,對于 Squeezenet,速度是30ms
展示案例


如果想先運行demo或快速使用這個框架,你可以掃下面的二維碼安裝編譯好的apk/ipa文件,不用知道詳細的安裝細節。
iOS-MobileNet:

Android-Googlenet:

想要了解源碼實現可以繼續往下看,源碼位于examples文件夾里。
執行樣例
1、復制項目代碼
2、安裝apk\ipa文件,或導入到IDE
3、運行
前期準備
android端安裝NDK
安裝Cmake
Android端 NDK CMake 文件地址:https://developer.android.google.cn/ndk/guides/cmake.html
安裝 Protocol Buffers
使用MDL lib步驟
在OSX或Linux上測試:
# mac or linux:
./build.sh mac
cd build/release/x86/build
./mdlTest
使用MDL lib
#android
Copy so file to your project. According to the example of writing your code.
#ios
The example code is your code.
多線程執行
# After a Net instance in MDL is created, you could set its thread numbers for execution like this.
net->set_thread_num(3); # Now MDL is tuned to run in 3 parallel threads.
開發
在android端編譯MDL資源
# android:
# prerequisite: install ndk from google
./build.sh android
cd build/release/armv-v7a/build
./deploy_android.sh
adb shell
cd /data/local/tmp
./mdlTest
在iOS端編譯MDL資源
# ios:
# prerequisite: install xcode from apple
./build.sh ios
copy ./build/release/ios/build/libmdl-static.a to your iOS project
把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
# also need the input data
./caffe2mdl model.prototxt model.caffemodel data
# 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模型下都很穩定
占用空間極小(4M),不需要依賴第三方的庫
支持從32比特float到8比特unit轉化
接下來會與與ARM相關的算法團隊進行線上線下溝通,優化ARM平臺
NEON使用涵蓋了所有的卷積、歸一化、池化等
利用循環展開,可以讓性能更加優化,防止不必要的CPU損失
對于overhead進程,可以轉發大量繁重的計算任務
項目地址:https://github.com/baidu/mobile-deep-learning
雷鋒網 AI科技評論編輯整理。
雷峰網版權文章,未經授權禁止轉載。詳情見轉載須知。