9

I currently have TensorFlow code in python and are trying to find the best way to add this to an android app. As I see it there are a few options to do this.

I've been looking at ML kit (https://developers.google.com/ml-kit/). But I'm not sure if this would work since I am using some specific TensorFlow functions to make calculations in the graph. For example these two lines:

t_score = tf.reduce_mean(t_obj)
t_grad = tf.gradients(t_score, t_input)[0]

Would that be possible to do with ML kit?

Another option would then be to use TensorFlow (lite) for Java without ML kit, but looking at the Java API it seems to be limited, would those two calls above be possible to do in java?

The last option would be to host the python code and use it as backend so that the Android app could send the data to it and receive the result. That would be more expensive since the computations can't be made on mobile. So if possible the other options are preferred.

How would you do this?

Ibrahim Ulukaya
  • 12,329
  • 1
  • 30
  • 34
emillime
  • 529
  • 6
  • 21
  • I would say use tensorflow mobile for now , because tensorflow lite is still in developer preview. I'm currently with TF mobile for object detection and I tried TFLite too and I got better results with TF mobile.. (I didn't try ML kit so sorry can't give you any useful information about it)... and to my understanding if you wanna use some specific operations that they're not packed already with the library you only have one choice is to add those operations in the .cpp files. and build the library with bazel , then add it to your android project.. – user 007 Jun 18 '18 at 11:11
  • Folks at bytedeco.org have created a package for calling C/C++ code right from Java without JNI. They've also created a preset package for Tensorflow on various platforms, including Android. Take a look at https://github.com/bytedeco/javacpp-presets/tree/master/tensorflow IMHO, this would be your best bet for doing more granular things with Tensorflow on Android. – kris larson Jun 22 '18 at 21:04