Application gets stuck while we are Instantiating a Caffe2 predictor

254 Views Asked by At

Application gets stuck while we are Instantiating a Caffe2 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 in C++

#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.")
}

Traceback

08-07 17:10:00.308 897-897/com.example.augustinas.nc2 E/Gideon: Loaded module
08-07 17:10:00.315 897-1110/com.example.augustinas.nc2 E/F8DEMO: Attempting to load protobuf netdefs...
08-07 17:10:07.198 897-1110/com.example.augustinas.nc2 E/F8DEMO: Couldn't parse net from data.
08-07 17:10:07.287 897-1110/com.example.augustinas.nc2 E/F8DEMO: done.
08-07 17:10:07.287 897-1110/com.example.augustinas.nc2 E/F8DEMO: Instantiating predictor...
08-07 17:10:09.251 897-1110/com.example.augustinas.nc2 A/native: [F given_tensor_fill_op.h:27] Check failed: output->size() == values_.size() output size: 22937600 given size: 5348403
08-07 17:10:09.251 897-1110/com.example.augustinas.nc2 A/native: terminating.
08-07 17:10:09.251 897-1110/com.example.augustinas.nc2 A/libc: Fatal signal 6 
(SIGABRT), code -6 in tid 1110 (AsyncTask #1)

Original source:

We use the libraries and code that is shown here: https://github.com/caffe2/AICamera

Model Used

We use a custom InceptionResNet model. The sizes of init_net.pb and predict_net.pb are 155,1 MB and 6,1 kB.

1

There are 1 best solutions below

3
On

Try Building the Caffe2 in your Machine. AICamera Project's Caffe2 Binaries are bit old for new trained models. I also faced similar issues but now i have the working code with my custom models.

Happy Coding :)