Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use TensorFlow python code with android app

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?

like image 473
emillime Avatar asked Jun 18 '18 11:06

emillime


People also ask

Can I use TensorFlow with Android?

TensorFlow Lite lets you run TensorFlow machine learning (ML) models in your Android apps. The TensorFlow Lite system provides prebuilt and customizable execution environments for running models on Android quickly and efficiently, including options for hardware acceleration.

Does TensorFlow support mobile phone?

TensorFlow Mobile is used for a mobile platform such as iOS and Android.

Can python be used to make Android apps?

Python can be used for Android App Development even though Android doesn't support native Python development. This can be done using various tools that convert the Python apps into Android Packages that can run on Android devices.

Can Android apps use machine learning?

Run machine learning models in your Android, iOS, and Web apps. Google offers a range of solutions to use on-device ML to unlock new experiences in your apps. To tackle common challenges, we provide easy-to-use turn-key APIs.


1 Answers

I have done a similar code lab from Google. So, I'm sharing working demos of your problem:

1.) https://codelabs.developers.google.com/codelabs/tensorflow-style-transfer-android/index.html?index=..%2F..%2Fio2017#0

2.) https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2/#0

3.) https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2-tflite/#0

Hope, it helps.

like image 188
Stuti Verma Avatar answered Sep 28 '22 17:09

Stuti Verma