Home

Awesome

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

iPhone5sMeizu M3 note
<img src="https://raw.githubusercontent.com/solrex/caffe-mobile/master/screenshot/CaffeSimpleiPhone5s.png" width="70%" /><img src="https://raw.githubusercontent.com/solrex/caffe-mobile/master/screenshot/CaffeSimpleM3-Note.jpg" width="40%" />

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

$ cp $CAFFE/examples/mnist/lenet_iter_10000.caffemodel \
     $CAFFE_MOBILE/examples/ios/simple/CaffeSimple/data/weight.caffemodel

For Android

Step 1: Build Caffe-Mobile Lib with cmake

Test passed ANDROID_ABI:

$ 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

$ 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

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