pytorch-android icon indicating copy to clipboard operation
pytorch-android copied to clipboard

Help please

Open heon01px2020 opened this issue 5 years ago • 7 comments

In this project, it seems to be using resnet or squeezenet. However, in a project I'm doing of my own, I am currently using mobilenetv2. Currently, I have converted the mobilenetv2 model from pytorch to caffe2. If I use this caffe2 file, would it work seamlessly after replacing the _init_net.pb and _predict_net.pb or do I need to make other modifications? Thank you.

heon01px2020 avatar Jan 04 '19 01:01 heon01px2020

would it work seamlessly after replacing the _init_net.pb and _predict_net.pb or do I need to make other modifications?

It should. MobileNet v2 (or SqueezeNet) input (data)/output (prediction) tensor dimension is the same. So, it work seamlessly (no code changes required to the native-lib.cpp).

Unfortunately, when I tested with a quantized MobileNet v2 today, the Android app crashed due to Caffe2 quantized fc op:

mobilenet_v2_caffe2_predictnet_crash

2019-01-04 16:27:24.093 32484-32545/facebook.f8demo A/native: [F int8_fc_op.h:43] Check failed: K == W.t.size(1) 
2019-01-04 16:27:24.093 32484-32545/facebook.f8demo A/native: terminating.
    
    
    --------- beginning of crash
2019-01-04 16:27:24.093 32484-32545/facebook.f8demo A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 32545 (Camera Backgrou), pid 32484 (facebook.f8demo)

I have not tested with non-quantized MobileNet v2 yet.

cedrickchee avatar Jan 04 '19 08:01 cedrickchee

Ok, thank you so much! I had another question which was that I have an image classification model, not an object detection model. Would there be any modifications needed?

heon01px2020 avatar Jan 04 '19 14:01 heon01px2020

Unless I understand it incorrectly, isn't MobileNet/ResNet18 a classification model?

cedrickchee avatar Jan 05 '19 15:01 cedrickchee

Yes, the Mobilenet v2 model I made is a classification model. I thought that your tutorial used object detection. Does that require me to make any modifications to the code? What I want to do is have the app take frames from the video, classify the image, and output the classification on the screen. Thank you!

heon01px2020 avatar Jan 07 '19 02:01 heon01px2020

My tutorials used image classification models. It should not require any modifications to the code if you put aside and do not count my previous reply where the MobileNet v2 is experiencing error. I can't confirm at this point if this problem is due to Caffe2 or my own code, but from the error messages, I can tell that the problem is in Caffe2 or ONNX exporter.

What I want to do is have the app take frames from the video, classify the image, and output the classification on the screen.

The Android app is doing exactly that. Try it and find out yourself! :slightly_smiling_face:

cedrickchee avatar Jan 07 '19 03:01 cedrickchee

Ok, thank you! I tried again without my model, but it couldn't build because I am missing jniLibs.armeabi-v7a/libcaffe2.a Do you know how to get it?

heon01px2020 avatar Jan 08 '19 11:01 heon01px2020

The steps to download libcaffe2.a and other library files are in the README.

If you prefer not to build PyTorch from master, I have committed the files for the Caffe2 bits into this git repo. Unfortunately, not all files are uploaded to GitHub due to file size limit. Grab the remaining large files from my [Google Drive](https://drive.google.com/drive/folders/1e1lFa8W2rkA8M7mhahe9VSiSMnl0a4Ab?usp=sharing.

I don't know how you missed it. May be I should have been clearer.

cedrickchee avatar May 11 '19 05:05 cedrickchee