(forked from sh1r0 https://github.com/sh1r0/caffe-android-lib)
Porting caffe to android platform
has few problems on Windows
git clone --recursive https://github.com/ouvtk/caffe-android-lib.git
cd caffe-android-lib
./build.py $(NDK_PATH)
-
in case you want to use it for your package change JNI functions names (ex. change package from com.sh1r0.caffe-android-demo to com.example.caffe)
./caffe-mobile/jni/caffe_jni.cpp Replace middle part from Java_com_sh1r0_caffe_1android_1demo_CaffeMobile_loadModel to Java_com_example_caffe_CaffeMobile_loadModel
-
put required stuff into your device
./get_model.py adb shell mkdir -p /sdcard/caffe_mobile/ adb push caffe-mobile/jni/caffe/models/bvlc_reference_caffenet/ /sdcard/caffe_mobile/bvlc_reference_caffenet/
-
copy
caffe-mobile/libs/armeabi-v7a/*.so
to your jni lib directory (ex. for recent gradle build is src/main/jniLibs/armeabi-v7a) -
in your main activity
static { System.loadLibrary("caffe"); System.loadLibrary("caffe_jni"); }
-
create
CaffeMobile.java
package ru.ouvtk.deepdreamapp; public class CaffeMobile { public native void enableLog(boolean enabled); public native int loadModel(String modelPath, String weightsPath); public native int predictImage(String imgPath); public native void dreamImage(String modelPath, Bitmap outBmp); }
-
call native methods
CaffeMobile caffeMobile = new CaffeMobile(); caffeMobile.enableLog(true); // optional, enable native logging caffeMobile.loadModel(modelPath, weightsPath); // init once ... caffeMobile.predictImage(imgPath); //or caffeMobile.dreamImage(imgPath, bmp);
.envrc
files are for direnv
direnv is an environment variable manager for your shell. It knows how to hook into bash, zsh and fish shell to load or unload environment variables depending on your current directory. This allows to have project-specific environment variables and not clutter the "~/.profile" file.