Porting Trained Caffe Net with Custom Layer to Android

asked 2019-06-19 17:41:08 -0600

eagle77 gravatar image

updated 2019-06-20 06:35:01 -0600

Hello, I'm trying to porting a CaffeNet in Android. The problem is in the net model that has a custom layer.

I've seen that opencv allows you to easily import a coffee network, but there is no way to add a custom layer directly from android similar to the C ++ method "dnn_registerLayer('xxxx', xxxxx)".

I already have the implementation of the layer in C ++ which could be the fastest or easiest way to port in android ? I thought about using OPENCV in C ++ and the JNI but I wouldn't want to replicate what OpenCV android currently does.

Do you have any ideas? Thank you. F

edit retag flag offensive close merge delete

Comments

1

which opencv version did you try ? problem might be solved in a more recent one.

we neeed more information, about the network you're trying with, and in general.

berak gravatar imageberak ( 2019-06-20 02:58:48 -0600 )edit

Hi berak, thank you for your replay. I try OpenCV 3.4.6. For my master thesis, I'm trying to port in android a CNN already trained for hand joint regressor, but my CaffeNet has a custom layer and I should try to make it work in android. I don't know if it is a good challenge.:D Thanks you very much. F.

eagle77 gravatar imageeagle77 ( 2019-06-20 04:12:42 -0600 )edit

if you can't work around the custom layer, you'll need jni, and add a custom layer from c++, unfortunately, theres no way to do that from pure java.

opencv's dnn has both crop and cropandresize layers. what's so special about yours ?

berak gravatar imageberak ( 2019-06-20 05:22:31 -0600 )edit
2

thanks berak, now I'm sure the right way is that. I try. Sorry, I wrote incorrectly that it does 'crop' because I copied it from the opencv documentation. The idea of the custom layer is to perform an orthographic projection of (preliminary) intermediate 3D predictions, from which 2D Gaussian heatmaps are created (within the layer). These heatmaps are then leveraged in the remaining part of the network (conv) to obtain the final 2D and 3D predictions. I don't know if I managed to explain the concept well. Now I have two alternatives, try using jni or retrain the network without the custom layer :( It's a challenge. Is there any doc to start with jni in android studio? I saw that they almost always talk about eclipse. .. As always, thanks.

eagle77 gravatar imageeagle77 ( 2019-06-20 06:52:34 -0600 )edit

Is there any doc to start with jni in android studio?

not really. but look at the android samples, e.g. the mixedprocessing and the facedetection ones have jni parts

berak gravatar imageberak ( 2019-06-20 06:56:19 -0600 )edit