Giter Site home page Giter Site logo

solrex / caffe-mobile Goto Github PK

View Code? Open in Web Editor NEW
317.0 26.0 122.0 701 KB

Optimized (for size and speed) Caffe lib for iOS and Android with out-of-the-box demo APP.

License: Other

CMake 5.24% C++ 93.90% Python 0.43% Shell 0.42%
caffe deep-learning android ios app cnn dnn mobile-app

caffe-mobile's Introduction

Caffe on Mobile Devices

Optimized (for size and speed) Caffe lib for iOS and Android with demo APP. (CPU_ONLY, NO_BACKWARD, NO_BOOST, NO_HDF5, NO_LEVELDB)

Screenshots

iPhone5s Meizu M3 note

NOTE: Cmake version 3.7.2 builds faster lib than version 3.5.1 (verified on Ubuntu 16.10/Android NDK r14). Don't know why. So please use a newer cmake if you can.

NOTE: NDK version r16+ is not supported. NDK r16 moves all standalone headers to unified headers. It causes a lot of cross compile problems which I cannot resolve. See issue #52.

For iPhone or iPhone Simulator

Step 1: Build Caffe-Mobile Lib with cmake

$ git clone --recursive https://github.com/solrex/caffe-mobile.git
$ ./tools/build_ios.sh

Step 2: Build iOS App: CaffeSimple with Xcode

  • For CaffeSimple to run, you need a pre-trained LeNet on MNIST caffe model and the weight file. Follow the instructions in Training LeNet on MNIST with Caffe to train your LeNet Model on MNIST. Then copy the the trained weight file caffe/examples/mnist/lenet_iter_10000.caffemodel to CaffeSimple app directory. Note: Check the batch size setting in net.prototxt, set it to 1 if needed.
$ cp $CAFFE/examples/mnist/lenet_iter_10000.caffemodel \
     $CAFFE_MOBILE/examples/ios/simple/CaffeSimple/data/weight.caffemodel
  • If you want to use your self-defined caffe network, use tools/prototxt2bin.py net.prototxt to convert your prototxt to protobin. Then place net.protobin in $CAFFE_MOBILE/examples/ios/simple/CaffeSimple/data/.

  • Load the Xcode project inside the $CAFFE_MOBILE/examples/ios/simple/ folder, connect your iPhone to Mac, change target to "Your Name's iPhone", and press Command-R to build and run it on your connected device.

For Android

Step 1: Build Caffe-Mobile Lib with cmake

Test passed ANDROID_ABI:

  • arm64-v8a
  • armeabi
  • armeabi-v7a with NEON (not stable)
$ git clone --recursive https://github.com/solrex/caffe-mobile.git
$ export NDK_HOME=/path/to/your/ndk  # C:/path/to/your/ndk on MinGW64 (/c/path/to/your/ndk not work for OpenBLAS)
$ ./tools/build_android.sh

For Windows Users:

Install the following softwares before you start:

  1. Git for Windows: A shell environment(MinGW64) to run the build.
  2. tdm64-gcc-5.1.0-2.exe: The GNU toolchain, remember to copy /path/to/TDM-GCC-64/bin/mingw32-make.exe to /path/to/TDM-GCC-64/bin/make.exe.
  3. cmake-3.8.2-win64-x64.msi: Cmake

Then start Git Bash application to run the build script.

Step 2: Build Android App: CaffeSimple with Android Studio

  • For CaffeSimple to run, you need a pre-trained LeNet on MNIST caffe model and the weight file. Follow the instructions in Training LeNet on MNIST with Caffe to train your LeNet Model on MNIST. Then copy the model file caffe/examples/mnist/lenet.prototxt and the trained weight file caffe/examples/mnist/lenet_iter_10000.caffemodel to the SD card root of your Android mobile phone. Check the batch size setting in net.prototxt, set it to 1 if needed.
$ adb push $CAFFE/examples/mnist/lenet_iter_10000.caffemodel \
     /sdcard/weight.caffemodel
$ adb push $CAFFE_MOBILE/examples/ios/simple/CaffeSimple/data/net.protobin \
     /sdcard/net.protobin
$ adb push $CAFFE_MOBILE/examples/ios/simple/CaffeSimple/data/test_image.jpg \
     /sdcard/test_image.jpg
  • If you want to use your self-defined caffe network, use tools/prototxt2bin.py net.prototxt to convert your prototxt to protobin. Then push net.protobin to your sdcard root directory.

  • Load the Android studio project inside the $CAFFE_MOBILE/examples/android/CaffeSimple/ folder, and press Command-R to build and run it on your connected device.

For MacOSX & Ubuntu

Step 1: Install dependency

$ brew install protobuf # MacOSX
$ sudo apt install libprotobuf-dev protobuf-compiler libatlas-dev # Ubuntu

Step 2: Build Caffe-Mobile Lib with cmake

$ git clone --recursive https://github.com/solrex/caffe-mobile.git
$ mkdir build
$ cd ../build
$ cmake ..
$ make -j 4

Step 3: Build Caffe-bin with cmake

$ brew install gflags
$ cmake .. -DTOOLS
$ make -j 4

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.