State of AI on Android and iOS

 State of AI on Android and iOSIn previous posts, we explored some of the compelling applications for Machine Learning on mobile apps, and considered whether the learning/computation should happen on-device or in the cloud. In this post, we’ll explore what are the options for implementing AI based applications on Android and iOS.

Setting Up ML Application on Andriod and iOS Platforms

The good news is that both Android and iOS platforms have announced first-class support for Machine Learning applications. Google announced Neural Networks API to accelerate on-device machine intelligence on Android 8.1 and Tensorflow Light for using in mobile and embedded devices. Apple announced the CoreML framework at their developer conference, WWDC 2017.

Now we will list the steps involved in setting up a simple machine learning application on mobile platforms: Andriod and iOS. For better understanding, we’ll consider the example of an app with Image Recognition using a neural network.

(Note: the below steps are more on the technical side, but just goes on to show the simple high-level steps required to get machine learning setup on your apps.)

Setup in Android

Below are the steps to be followed in setting up Andriod Machine Learning platform:

  1. Add TensorFlow lib as a dependency to your project.
  2. Identify the suitable pre-trained model. Model will be “.pb” file. It will come with a label file (.txt format). Drop them into the assets folder.
  3. Use the TensorFlowInferenceInterface that comes with the TF library. This class encapsulates the logic required to process the image and give the output label with confidence level.
  4. Process/display the label and confidence level. It'll be a value between 0 and 1.

In Android, the machine learning computation is completely based on pre-trained Tensorflow models, combined with a standard SDK. There is no platform level API to get output from a model (unlike Apple). However, Android has an advanced Neural Net API, which lets you train models on the device, on the go. Pretty powerful and advanced, but not many devices supported (as of the writing of this blog, at least).

Setup in iOS

Below is the list of steps to be followed in setting up iOS Machine Learning platform:

  1. Here, we will have to use models in the .mlmodel format. This is an Apple-prescribed format. As this is a non-standard format, Apple actually provides some tools to convert other formats in to .mlmodel format, including from TensorFlow models.
  2. Identify a suitable model, drop it into Project Navigator and assign the target ownership correctly.
  3. If you click on the model object, it will directly show all details of the model like Input & output name.
  4. Now XCode will auto-generate a Swift class representing this model. This class will be your interface to provide input and get output from the model.
  5. Now, all we need to do is pass the input to the model object, and get the output.

We see that both Android and iOS platforms are adopting Machine Learning in a big way, by providing built-in support for them. They’ve made it easy for developers to drag-drop trained models and use them on the fly in few simple steps. And there are several tools available to convert and reuse these models across the platforms.

Free mobile app consultation


About Authors

Kunj Gupta1. Kunj Gupta is a Google Certified Senior Mobile Developer at V-Soft. He works on developing apps for Android and iOS platforms, following best practices to ensure that apps run efficiently with respect to memory, CPU, battery, and network. He is also an expert in DevOps side of mobile app development, especially on automated Unit Tests and UI Tests on the Continuous Integration pipeline. Currently, he is working on applying Machine Learning in mobile apps as well.

 

Shaik Ghouse Basha2. Shaik Ghouse Basha is a Mobile Lead at V-Soft. He works on developing apps for Android and iOS platforms, following best practices to ensure that apps run efficiently with respect to memory, CPU, battery, and network. He is also an expert in DevOps side of mobile app development, especially on automated Unit Tests and UI Tests on the Continuous Integration pipeline. He is researching on applying Machine Learning in mobile apps as well.

 


Topics: Technology, Main, Mobile Apps, Machine Learning, Artificial Intelligence

Subscribe to Our Blog

Mobile Apps

Recent Posts