# Getting error on caffe2 AICamera example

**URL:** <https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828>\
**Category:** Uncategorized\
**Created:** [December 22, 2018, 4:17pm UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828 "2018-12-22T16:17:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![soloupis](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/958977/32.png) [@soloupis](https://discuss.pytorch.org/u/soloupis)\
**Post date:** [December 22, 2018, 4:17pm UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828/1 "2018-12-22T16:17:36Z")

</div>

Hello there,  
This example [https://caffe2.ai/docs/AI-Camera-demo-android.html](https://caffe2.ai/docs/AI-Camera-demo-android.html)  
works fine with squeezenet in android device.Also it works fine with squeezenet files from this directory  
[https://github.com/caffe2/models](https://github.com/caffe2/models)

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  
[https://github.com/caffe2/models](https://github.com/caffe2/models)

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

---

<div class="post-metadata">

**Author:** ![smth](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/smth/32/13_2.png) [@smth](https://discuss.pytorch.org/u/smth)\
**Post date:** [December 23, 2018, 8:05am UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828/2 "2018-12-23T08:05:16Z")

</div>

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

99% of the work was done by @tom

See [https://github.com/pytorch/pytorch/pull/15509](https://github.com/pytorch/pytorch/pull/15509) and [https://github.com/t-vi/AICamera](https://github.com/t-vi/AICamera)  
Once that PR is merged into PyTorch master, you can use the README in [https://github.com/t-vi/AICamera](https://github.com/t-vi/AICamera) to get a working Android app, including changing the protobuf with your own `init.pb` / `predict.pb` files.

---

<div class="post-metadata">

**Author:** ![soloupis](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/958977/32.png) [@soloupis](https://discuss.pytorch.org/u/soloupis)\
**Post date:** [December 23, 2018, 11:24am UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828/3 "2018-12-23T11:24:10Z")

</div>

@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!!

---

<div class="post-metadata">

**Author:** ![soloupis](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/958977/32.png) [@soloupis](https://discuss.pytorch.org/u/soloupis)\
**Post date:** [December 23, 2018, 3:29pm UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828/4 "2018-12-23T15:29:59Z")

</div>

@smth  
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/libnative-lib.so’, 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.

Thanks

---

<div class="post-metadata">

**Author:** ![tom](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/tom/32/3162_2.png) [@tom](https://discuss.pytorch.org/u/tom)\
**Post date:** [December 23, 2018, 6:25pm UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828/5 "2018-12-23T18:25:46Z")

</div>

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

Thomas

---

<div class="post-metadata">

**Author:** ![smth](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/smth/32/13_2.png) [@smth](https://discuss.pytorch.org/u/smth)\
**Post date:** [December 23, 2018, 8:02pm UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828/6 "2018-12-23T20:02:00Z")

</div>

did you follow the instructions in [https://github.com/t-vi/AICamera#using-caffe2-from-pytorch-master](https://github.com/t-vi/AICamera#using-caffe2-from-pytorch-master) ?  
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.

---

<div class="post-metadata">

**Author:** ![soloupis](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/958977/32.png) [@soloupis](https://discuss.pytorch.org/u/soloupis)\
**Post date:** [December 24, 2018, 5:47am UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828/7 "2018-12-24T05:47:42Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![soloupis](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/958977/32.png) [@soloupis](https://discuss.pytorch.org/u/soloupis)\
**Post date:** [December 24, 2018, 5:50am UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828/8 "2018-12-24T05:50:31Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![javier.a.velasco.z](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/javier.a.velasco.z/32/9238_2.png) [@javier.a.velasco.z](https://discuss.pytorch.org/u/javier.a.velasco.z)\
**Post date:** [April 12, 2019, 5:21pm UTC](https://discuss.pytorch.org/t/getting-error-on-caffe2-aicamera-example/32828/9 "2019-04-12T17:21:29Z")

</div>

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 build\_android.sh 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 [https://github.com/onnx/tutorials/blob/master/tutorials/PytorchCaffe2MobileSqueezeNet.ipynb](https://github.com/onnx/tutorials/blob/master/tutorials/PytorchCaffe2MobileSqueezeNet.ipynb) 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 [https://github.com/cedrickchee/pytorch-android](https://github.com/cedrickchee/pytorch-android) and it DID work in Android.

Thanks.
