Getting error on caffe2 AICamera example

Hello there,
This example
works fine with squeezenet in android device.Also it works fine with squeezenet files from this directory

The problem occurs when I have to put inside my own init.pb and predict.pb files from different model. My model is densnet.
The error is:
[F given_tensor_fill_op.h:27] Check failed: output->size() == values_.size() output size: 159744 given size: 75129

Also it throws different error with files from densnet from the above repo

Does anyone has accomplished to work the AI Camera Caffe2 project or any other pytorch/caffe2 project with different model in ANDROID??
Is this caffe2 inside the specific android project only works with squeezenet?

Thanks in advance

I have updated AICamera example to work with latest pytorch master.

99% of the work was done by @tom

See and
Once that PR is merged into PyTorch master, you can use the README in to get a working Android app, including changing the protobuf with your own init.pb / predict.pb files.

1 Like

@smth thank you for taking the time to help with my problem these days before Christmas.
I will try your solution this afternoon and I will notify you again about the results.

A lot of people from Udacity/Facebook scholarship challenge that is currently running are interested in this!!

I tried to use latest NDK 18.
Unfortunately it gives the below error:
““Build command failed.
Error while executing process C:\Users\farmaker1\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {–build C:\Users\farmaker1\Desktop\Sumith\app.externalNativeBuild\cmake\debug\armeabi-v7a --target native-lib}
ninja: error: ‘…/…/…/…/src/main/jniLibs/armeabi-v7a/libcaffe2.a’, needed by ‘…/…/…/…/build/intermediates/cmake/debug/obj/armeabi-v7a/’, missing and no known rule to make it””

This error did not occur with NDK 17. and different CMakelists file (Which project I have managed to run it in mobile…BUT only works with Squeezenet init and predict files which was my main concern)

I would be glad if you gave me your thoughts about that.


I won’t debug doing stuff on Windows (sorry), but from what I can see, the Android app build cannot find libcaffe2.a: You’re supposed to get a libcaffe2.a for armeabi-v7a (and for x86) from building caffe for Android from PyTorch master (twice) and then copy it to the respective directory.

Bst regards


1 Like

did you follow the instructions in ?
In that script, we first build the caffe2 libraries and copy them over the AICamera folder.
I think you missed or forgot that step, and hence the error.

1 Like

@smth thank you I will try that.
One last question. Is this AICamera project only for squeezenet OR we can use our own densnet model?
Happy holidays

@tom Thank you for taking time to answer my question. As Pytorch is getting more users these questions will become more and more frequent. A last question. Do you know if this AICamera example is for Squeezenet only or we can use our Densnet files?
Happy holidays!

Hi, I’ve been working with the AICamera example for PyTorch with MobileNet V2. As Ji Lin’s MobileNet V2 implementation includes a dropout layer, I wasn’t able to export the model to Android in the stable PyTorch 1.0 release (execution with predictor failed in both Python and Android). So, I had to remove that layer. Also, I couldn’t export the pretrained SqueezeNet model from PyTorch as it uses ceil_mode=True and ONNX export failed with that.

This week I cloned the PyTorch master from GitHub, as I saw those issues were fixed. I built the library and installed it, then I was able to export the models and execute them with predictor in Python. Then I also built the Caffe 2 API for Android using the script from the repo and copied the files to the AICamera project. I then copied the MobileNet V2 with dropout init_net and predict_net to the Android project and it worked perfectly. Nevertheless, when I tried to use the pretrained SqueezeNet model that I had exported, the Android app crashed in the model execution with predictor (even though it executed without trouble in Python).

I want to know how to fix it as I’ve seen SqueezeNet has been used with AICamera.

Some details that might help:

  • In stable PyTorch, the ONNX exported graph included the dropout and that was the reason why it couldn’t be executed with predictor. Now the dropout is not in the graph and I think that’s why it is executed correctly in both Python and PyTorch. What I mean is that it might have nothing to do with me building/updating the Caffe 2 API for Android.

  • I tried with the SqueezeNet implementation from which has ceil_mode=False and the execution in Android also fails.

  • I tried with both the original SqueezeNet pretrained model and a transfer-learning-trained one but none of them worked (it must be something in the architecture).

  • I tried with an old SqueezeNet init_net.pb and predict_net.pb from and it DID work in Android.