AICamera
AICamera copied to clipboard
Application gets stuck
Application gets stuck while we are Instantiating predictor!
Tools
I use: Android Studio 3.0.1 Build #AI-171.4443003, built on November 9, 2017 JRE: 1.8.0_152-release-915-b01 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.15.0-29-generic android-ndk-r13b
Code
#define alog(...) __android_log_print(ANDROID_LOG_ERROR, "F8DEMO", __VA_ARGS__);
void loadToNetDef(AAssetManager* mgr, caffe2::NetDef* net, const char *filename) {
AAsset* asset = AAssetManager_open(mgr, filename, AASSET_MODE_BUFFER);
assert(asset != nullptr);
const void *data = AAsset_getBuffer(asset);
assert(data != nullptr);
off_t len = AAsset_getLength(asset);
assert(len != 0);
if (!net->ParseFromArray(data, len)) {
alog("Couldn't parse net from data.\n");
}
AAsset_close(asset);
}
void Java_initCaffe2(JNIEnv* env, jobject /* this */, jobject assetManager){
AAssetManager *mgr = AAssetManager_fromJava(env, assetManager);
alog("Attempting to load protobuf netdefs...");
loadToNetDef(mgr, &_initNet, "init_net.pb");
loadToNetDef(mgr, &_predictNet,"predict_net.pb");
alog("done.");
alog("Instantiating predictor...");
_predictor = new caffe2::Predictor(_initNet, _predictNet);
alog("done.")
}