The sample app given by google for tensorflow on android is written in C++.
I have a tensorflow application written in python. This application currently runs on desktop. I want to move the application to android platform. Can I use bazel to build the application that is written in python directly for android? Thanks.
Also sample tensorflow app in python on android will be much appreciated.
Currently, there is no simple way to run tensorflow on android. Typically, you would only have to use inference (runtime), not training.
Another way is to use TensorFlow serving to host models in the cloud and issue RPC calls from an Android client.
I tried to use python in my android application with some 3rd party terminals like SL4A and Qpython. Those will support to run the python files directly in our android application so we have to install SL4A apk's and we need to call that intent.But these will support for some level I guess.
I tried to import tensorflow in that terminal it shows module not found. So I thought this tensorflow will not work in these terminals.
So I am trying to create one .pb file from the python files which are working in unix platform.So We need to include that output .pb file in our android application and we need to change the c++ code regarding that .pb file.I am thinking in this way.let see it will work or not.I will update soon if it working.
You can create your tensorflow model on your desktop and save it as a .pb file. Then you can add this model to your android project and make use of it to make predictions on the android device.
Its like training(which involves heavy computations) on a desktop machine(which is more powerful) and using the model to make predictions(which involves less computations) on a mobile device(comparatively less powerful).
This is a link to a great video by Siraj Raval
https://www.youtube.com/watch?v=kFWKdLOxykE
Related
I want to create a simple neural network based on the example https://github.com/googlesamples/android-ndk/tree/master/nn_sample. Is it possible to create this with the help on Tensorflow only with Android tools on Java
Take a look at this folder https://github.com/googlesamples/android-ndk/tree/master/nn_sample/app/src/main/cpp
simple_model.h is the model trained in Tensorflow before creating the Android project. Now the model likes black-box, get input and predict output only, if you want to build your own model, try this tutorial (All steps from training, evaluating, prediction to deploy onto Android):
https://medium.com/#elye.project/applying-tensorflow-in-android-in-4-steps-to-recognize-superhero-f224597eb055
Affirmative. You can use TensorFlow Lite on Android, it's an open source deep learning framework which helps to compress and deploy models to a mobile or embedded application. It basically can take models as input and then deploys and interpret and perform resource-conserving optimizations for mobile applications. The NNAPI of Android NDK can interface with TFLite easily too. This link contains gesture, image, object & speech detection and classification example implementations on Android with Java using TFLite.
I created a Tensorflow image classification app in python 2.7 using Kivy and Pycharm. I used my own data to create a custom graph and labels file. The app works great and does what I want it to do. It took me months of learning and coding to get to this point. My last part of this "journey" has been trying to port the app to the android platform (I'd like to do Windows or a web app too -- but that does not seem to be a real option today . . .) I've created the Tensorflow Android Camera Demo app using Bazel and it worked fine on my Galaxy S5. However, after spending several long days searching all the references I could fine in Google searches, Packt (and other) books, and so on I am at an impasse. My question is does anyone in this forum have any advice on a method to create an Android app from a working Python app as I described? I would be really grateful for any help from someone who has done this.
I used my own data to create a custom graph and labels file
Since you have already trained your TensorFlow model, you can import it into an Android app relatively easily.
The TensorFlow Android demo app can now be built in Android Studio without using Bazel. You should be able to replace the Inception v3 image classifier model with your own model.
Check out my blog post here for more information about how to use the Java TensorFlowInferenceInterface class to interact with your pre-trained model:
https://medium.com/#daj/using-a-pre-trained-tensorflow-model-on-android-e747831a3d6
As for how to port a Python app to Android, I'm not aware of an easy way to do that.
I'm writing Android app.
The problem is that it should execute some calculations and library for this is written in Python.
What is the best way to invoke Python from Android/Java?
I heard about Kivy and even managed to run application, but python code returns latex formulae, that can't be rendered within Kivy app.
You can probably render LaTeX in Kivy fairly easily using a png exporter (such as presumably exists for web export tools, and modes like emacs' preview mode).
If you need to run python as part of a java app, probably a practical way to do it is to use kivy's python-for-android tools with your own java frontend, invoking the python interpreter via JNI. This would require some thinking and experimentation but should be possible. There are also other projects for building python for android, which might be able to do the same things.
Can I port existing python scripts on android using SL4A or ASE ? What I specifically want to do is to create an android application with normal UI elements and run the python scripts from the application itself, get the output and display it. Is this possible ?
Personnaly I think that you ask implicitly for three points:
Compatibility Desktop/Mobile
The first is the compatibility between the python library on the phone and the python library in your computer. If you don't use third party library and be sure to include the extra python library provided by sl4a, you should generally be ok.
Packaging
The second point is about how to package a Python app for android. It can easily be done with a wrapper as well described on the sl4a website. In fact they distribute a copy of a chapter of a book about SL4A that describes how to do that. So that is possible, but bear in mind that the user will be required to install python if he hasn't done so already (this is a sort of alert at the launch of the app)
UI
The third thing that you should have in mind is that you are not a 100% free concerning the widget/layout you can use with sl4a. Namely you can't really do whatever you would be able to do in Java or Scala. So you might have to consider altering your UI and do a webview instead (that can communicate back and forth with the python) with a framework to obtain a "mobile look and feel"
Hope this helps.
I think, what you want to do is make an independently apk file, that includes the python interpret and your script code.
I don't know if this can be done in Android. The only whay I know is running your script from Android Scripting Environment.
If web interface is normal UI then look at this discussion http://groups.google.com/group/android-scripting/browse_thread/thread/f86812549d2686e2/f828f916411d7a95 . You can use Python, webView, HTML5 and JavaScript
I had a similar problem and finally solved it by writing a small singleton class in Java that runs the Python-4-Android binary from the SL4A installation in a subprocess created using java.lang.ProcessBuilder. So I'm not using the SL4A mechanisms at all (triggers, upcalls, etc), just borrowing Python.
This seems cleaner than trying to start and connect to a Python process through SL4A.
This is Python 2.7.1, cross-compiling extensions from Mac OS X Snow Leopard. My Python modules are doing only text input and output, accepting socket connections, etc. No interaction with the Android API. It all works fine: writing a Java stream to Python input and reading a Java stream to get Python output. C extensions are build using the P4A instructions . (Android could not find .so dynalibs until I added
[build_ext]
inplace=1
to setup.cfg during the build. I think this is because setup 'install' is never invoked on the Android. I'm just pushing with adb.
All the activity lifecycle states seem to be working, but I can't yet determine whether the sub-process is automatically suspended while the main process is in the stopped state.
I can post code in a couple of weeks if this is of interest. (Just departing on vacation.)
My plan for packaging is to put a ZIP archive of the Python code in /assets and have the app unzip during the first onCreate. I haven't implemented this yet, but I don't expect any problems.
I am building an application for Android. It will interface with some C++ libraries using Android NDK through JNI. There are also some libraries that are written in Python that I want to call from my Android application (e.g. NTLK). How can I do that?
Please note that SL4A (Scripting Layer for Android) is something different. It allows you to build an application using a scripting language like Python, Lua etc. In my case the application will be in Java but will need to call code that has been written in Python. Is this possible in an elegant way?
I recommend putting the NLP code into web services on a Linux server and calling those from android.
This is quite straight forward in a framework like django.